I have 4 checkboxes and I want to toggle them (checked or not checked), and they should all be the same, whatever they are. I still do this:
var toggle_click = false; function check_them(element){ if(toggle_click){ $('#'+element+'_1').attr('checked', true); $('#'+element+'_2').attr('checked', true); $('#'+element+'_3').attr('checked', true); $('#'+element+'_4').attr('checked', true); } if(!toggle_click){ $('#'+element+'_1').attr('checked', false); $('#'+element+'_2').attr('checked', false); $('#'+element+'_3').attr('checked', false); $('#'+element+'_4').attr('checked', false); } if(!toggle_click){ toggle_click = true; } if(toggle_click) { toggle_click = false; } }
On the page load, some flags may or may not be checked - but as soon as I click on the link and launch this function, I want these flags to all go to the same state.
When I try to do this, it simply does not put checkmarks in the boxes, and sometimes it ticks them off, and this function again does nothing. What's happening? I am deprived of coffee and confused!
Should a group of flags be used or something like that?
Thank you all for your help.
javascript jquery
Abs
source share