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
Post a Comment