javascript - how to check all checkboxes and keep them checked through pagination -
i have scripts below 1 checks checkboxes in group works great, , pass checkbox values on pagination , works fine problem when click check box checks pages on page 1 when click page 2 check box checked although query working fine. if click checkboxes individually pass through pagination fine, don't know why check button doesn't. when click check all, boxes stay checked through pagination well.
here script checks checkboxes
<script type="text/javascript"> window.addevent('domready', function() { $$('li.head input[type=checkbox]').addevent('click', function() { this.getparent('ul').getelements('input[type=checkbox]').setproperty('checked', this.checked); }); }); </script>
here script remembers checkboxes
var aa_checkbox; function init_checkbox(){ //setup blank cb cookie if(!cookie.read('cb')){ cookie.write('cb', json.encode({})); } //setup "associative array" match in cookie aa_checkbox = json.decode(cookie.read('cb')); //set each checkbox class="remember_cb" $$('input.remember_cb').each(function(el){ //mark checked if in cookie if(aa_checkbox[el.name]){ el.checked = 'checked' } //setup onclick event put checkbox status in el.addevent('click', function(){ if(el.checked){ aa_checkbox[el.name] = 1; }else{ delete(aa_checkbox[el.name]); } }) }) //save aa_checkbox cookie upon leaving page window.onbeforeunload = function(){cookie.write('cb', json.encode(aa_checkbox));}; setup_form(); return true; } function setup_form(){ //set form adds inputs upon submit. $$('form.remember_cb_form').each(function(form){ form.addevent('submit', function(ev){ //clean inserted inputs var aa_hidden_insert = $$('input.hidden_insert'); $each(aa_hidden_insert, function(el){ el.parentnode.removechild(el); }) var el_form = this; //insert hidden elements representing values stored in aa_checkbox $each(aa_checkbox, function(i_value, s_name){ if(i_value){ var el_input = document.createelement('input'); el_input.type = 'hidden'; el_input.value = i_value; el_input.name = s_name; el_input.setattribute('class', 'hidden_insert'); el_form.appendchild(el_input); } }); }); }); } window.addevent('domready', init_checkbox);
if can me greatful, thanks
it has how code works. recommend check/un-check should affect in-memory copy of backing data. eg if have array representing check boxes, set check/uncheck in array render array check/uncheck corresponding check box. way, when check all, array cells set checked! when change page page, read status of corresponding array cell.
Comments
Post a Comment