hassank1 Posted May 10, 2008 Share Posted May 10, 2008 Hi I want to build a page with many checkboxes .. however there's one main checkbox if I press. all other checkboxes will be checked too.. how can I do that thx Link to comment https://forums.phpfreaks.com/topic/105036-check-all-checkboxes/ Share on other sites More sharing options...
RichardRotterdam Posted May 11, 2008 Share Posted May 11, 2008 here is a start for you <script> function setCheckBox(){ if(document.getElementById('main_checkbox').checked){ document.getElementById('my_checkbox').setAttribute('checked','checked'); }else{ document.getElementById('my_checkbox').removeAttribute('checked'); } } </script> subcheckbox <input type="checkbox" id="my_checkbox" /><br /> main checkbox <input type="checkbox" id="main_checkbox" onChange="setCheckBox()" /><br /> Link to comment https://forums.phpfreaks.com/topic/105036-check-all-checkboxes/#findComment-538024 Share on other sites More sharing options...
bibby Posted May 11, 2008 Share Posted May 11, 2008 ought to do it //js function checkAll() { // get all the inputs var cb = document.getElementsByTagName('input'); // loop through them for(var i=0;i<cb.length;i++) { // looking only for checkboxes if(cb[i].type=='checkbox') { // check it cb[i].checked=true; } } } //html <input type="checkbox" name="checkAll" onclick="checkAll()" /> Link to comment https://forums.phpfreaks.com/topic/105036-check-all-checkboxes/#findComment-538027 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.