check all button
Posted: Wed Mar 31, 2004 3:51 pm
I am trying to create a "check all" and "uncheck all buttons" for checkboxes on a php page on my site. I know how to write the code for it when the checkboxes are static but I am confused how to do it when the checkboxes are dynamic. Here is the code
<script type="text/javascript">
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field.checked = true;}
checkflag = "true";
return "Uncheck All"; }
else {
for (i = 0; i < field.length; i++) {
field.checked = false; }
checkflag = "false";
return "Check All"; }
}
</script>
The HTML code for the checkbox is :
<input type="checkbox" name="mail[]" value="<?=$cemail?>">
For the buttons are :
<input type=button value="Check All" onClick="this.value=check(this.form.list)">
I am getting a javascript error. Please any help will be appreciated.
<script type="text/javascript">
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field.checked = true;}
checkflag = "true";
return "Uncheck All"; }
else {
for (i = 0; i < field.length; i++) {
field.checked = false; }
checkflag = "false";
return "Check All"; }
}
</script>
The HTML code for the checkbox is :
<input type="checkbox" name="mail[]" value="<?=$cemail?>">
For the buttons are :
<input type=button value="Check All" onClick="this.value=check(this.form.list)">
I am getting a javascript error. Please any help will be appreciated.