Dysan Posted December 27, 2007 Share Posted December 27, 2007 Can a script be made, that selects all check boxes, upon a single check box being clicked? Quote Link to comment Share on other sites More sharing options...
wrong_move18 Posted December 27, 2007 Share Posted December 27, 2007 You can use this.. I use this in my work projects. If you want to select specific fields.. I used an array type of input name. HTML Form: <form name="test"> <input type="checkbox" id="checkall" value="" onclick="toggleCheck('chk[]', this.checked);" /> Check All<br /> <input type="checkbox" name="chk[]" value="1" /> Check 1 <br /> <input type="checkbox" name="chk[]" value="2" /> Check 2 <br /> <input type="checkbox" name="chk[]" value="3" /> Check 3 <br /> <input type="checkbox" name="chk[]" value="4" /> Check 4 <br /> <input type="checkbox" name="chk[]" value="5" /> Check 5 <br /> </form> Javascript Function: function toggleCheck(name, value){ var inputs = document.getElementsByTagName("input"); for(var i=0; i<inputs.length; i++){ if((inputs[i].type=="checkbox") && (inputs[i].name==name)) inputs[i].checked = value; } } if you want to select all checkboxes... HTML Form: <form name="test"> <input type="checkbox" id="checkall" value="" onclick="toggleCheck(this.checked);" /> Check All<br /> <input type="checkbox" name="chk1" value="1" /> Check 1 <br /> <input type="checkbox" name="chk2" value="2" /> Check 2 <br /> <input type="checkbox" name="chk3" value="3" /> Check 3 <br /> <input type="checkbox" name="chk4" value="4" /> Check 4 <br /> <input type="checkbox" name="chk5" value="5" /> Check 5 <br /> </form> Javascript Function: function toggleCheck(value){ var inputs = document.getElementsByTagName("input"); for(var i=0; i<inputs.length; i++){ if(inputs[i].type=="checkbox") inputs[i].checked = value; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.