check/uncheck all button
Posted: Mon Aug 22, 2005 8:46 pm
I got the following code from thejavascriptsource.com
Then I place this on my form where you can check/uncheck all of the checkboxes
The name of the checkboxes are actually delmessageid[] but if I put that in there, it says "syntax error". Currently the way it works is when you click it, the error is "length is null or not an object". I'm guessing that's because I didn't add the [] on to the name of my field. How can I get around this to make this work properly?
Code: Select all
<SCRIPT type="text/javascript">
<!--
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
return "Uncheck All"; }
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
return "Check All"; }
}
//-->
</script>Code: Select all
<input type=button value="Check All" onClick="this.value=check(this.form.delmessageid)">