[RESOLVED] checkboxes to check/uncheck all

wxdqz

New Member
I spent some time last week looking through several JavaScript code sources to find some code that would allow me to do the "check/uncheck" all thing from another checkbox. What I pieced together works here, but I wanted to verify that this is the best way to code this.

Here's my simple list of checkboxes:

<form action="check_all_test.html" method="post" name="listingform" id="listingform">

<input type="checkbox" name="check_all_top" onClick="checkAllSwitchTop()" /><br />
<input type="checkbox" name="manage[]" value=http://www.webdeveloper.com/forum/archive/index.php/"3" /><br />
<input type="checkbox" name="manage[]" value="1" /><br />
<input type="checkbox" name="manage[]" value="2" /><br />
<input type="checkbox" name="check_all_bottom" onClick="checkAllSwitchBottom()" />

</form>

And here's my JavaScript in the header of the page:

<script language="JavaScript" src=http://www.webdeveloper.com/forum/archive/index.php/"" type="text/javascript">
function checkAllSwitchTop() {
var checkVal = false;
if(document.listingform.check_all_top.checked == true) {
checkVal = true;
}
count = document.listingform.elements.length;
for (i=0; i < count; i++) {
document.listingform.elements.checked = checkVal;
}
}
function checkAllSwitchBottom() {
var checkVal = false;
if(document.listingform.check_all_bottom.checked == true) {
checkVal = true;
}
count = document.listingform.elements.length;
for (i=0; i < count; i++) {
document.listingform.elements.checked = checkVal;
}
}
</script>

So my questions are...

1) Is there a way to do this w/ ONE function? I want to have a working check/uncheck all box at the top AND the bottom of my list.
2) Is there also a way to specify that I only wan to check/uncheck all the checkboxes w/ the name="manage[]"?


Thanks,

Shaun
 
Top