PDA

View Full Version : HELP: Select All CheckBoxes with Dissimilar Names


johnmilano
09-11-2002, 10:37 PM
Please Help Me Figure Out How To Select All CheckBoxes with Dissimilar Names.

How can I select all checkboxes on one page and deselect them buy clicking one button for each choice? Remeber the name for each check box on the page will be different so they will not be in the same group.

Please help me,
John

beetle
09-11-2002, 10:50 PM
function checkAll() {
var inputs = document.getElementsByTagName("INPUT");
for (var i=0; i<inputs.length; i++)
if (inputs[i].type.toUpperCase() == "CHECKBOX")
inputs[i].checked = true;
}This can be modified to check/uncheck all, or reverse the checked state of all etc....

johnmilano
09-11-2002, 11:03 PM
I tired the code and it loads the code I placed on the page into a new window when I click on the button that calls the function?

Thanks for the help so far.

beetle
09-11-2002, 11:12 PM
<HTML>
<HEAD>
<TITLE>Check all checkboxes</TITLE>

<SCRIPT>
function checkAll() {
var inputs = document.getElementsByTagName("INPUT");
for (var i=0; i<inputs.length; i++) {
if (inputs[i].type.toUpperCase() == "CHECKBOX")
inputs[i].checked = true;
}
}
</SCRIPT>

</HEAD>

<BODY onLoad="">
<form>
<input type="checkbox" name="one" />
<input type="checkbox" name="one" />
<input type="checkbox" name="one" />
<br>
<input type="checkbox" name="two" />
<input type="checkbox" name="two" />
<input type="checkbox" name="two" />
</form>
<form>
<input type="checkbox" name="three" />
<input type="checkbox" name="three" />
<input type="checkbox" name="three" />
<br>
<input type="checkbox" name="four" />
<input type="checkbox" name="four" />
<input type="checkbox" name="four" />
<br>
<input type="text" name="text1" />
<input type="password" name="text2" />
<input type="button" value="Check all" onClick="checkAll();" name="text3" />
</form>
</BODY>
</HTML>

johnmilano
09-11-2002, 11:20 PM
Thank you bery much. I worked on this for about 4 hours today at work. You have made my life much easier today.:thumbsup: