javascript - check box is not working in edit page -


the select check box working @ initial time. steps: 1.consider check check boxes or check check box , saving form 2.editing saved form shows nothing checked. shows check box in initial stage. nothing saved.

javascript

<%= check_box_tag "box_select_all" %>  <%= check_box_tag "box_id[]", box.id, false, class: 'box_select' %> 

jquery

$('body').delegate('#box_select_all', 'click', function() {   $('.box_select').prop('checked', this.checked); });   $('body').delegate('.box_select', 'click', function() {   if ($(".box_select").length == $(".box_select:checked").length) {     $("#box_select_all").prop("checked", "checked");   } else {   $("#box_select_all").prop("checked", false);   } }); 

can me??

why want delegate function on body, when click checkbox, function called. call this:

$("#box_select_all").click(function() {   $(".box_select").prop('checked', this.checked); });  $(".box_select").click(function() {   if ($(".box_select").length == $(".box_select:checked").length) {     $("#box_select_all").prop("checked", "checked");   }    else {   $("#box_select_all").prop("checked", false);   } }); 

hope work.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -