R
Rob
Hello all, I have a form with a bunch of checkboxes.
When the form is submitted, I need to have at *least* one
checkbox checked. I wrote script to do just that and it works
fine except for one part.
When my form consists of only 1 checkbox, the form validation
script does not work correctly.
function check(){
var counter = 0;
var i;
for(i=0;i<contactsListing.checkbox.length;i++){
if(contactsListing.checkbox.checked){
counter++;
}
}
if(counter == 0){
alert("You must select at least 1 entry.");
return (false);
}
else{
return (true);
}
}
My form looks like this:
<form name="contactsListing" onSubmit="return check()"
method="post" action="http://www.myserver.abc/stuffToDo">
<table width=300>
<tr><td>
<input type="checkbox" name=checkbox value="001"> 001
</td></tr>
</table>
<input type="submit" name="submit" value="Delete">
</form>
Checking the only available box and clicking the 'Delete' button
gives me a "You must select at least 1 entry" alert.
What am I doing wrong?
Thanks for any pointers,
-Rob
When the form is submitted, I need to have at *least* one
checkbox checked. I wrote script to do just that and it works
fine except for one part.
When my form consists of only 1 checkbox, the form validation
script does not work correctly.
function check(){
var counter = 0;
var i;
for(i=0;i<contactsListing.checkbox.length;i++){
if(contactsListing.checkbox.checked){
counter++;
}
}
if(counter == 0){
alert("You must select at least 1 entry.");
return (false);
}
else{
return (true);
}
}
My form looks like this:
<form name="contactsListing" onSubmit="return check()"
method="post" action="http://www.myserver.abc/stuffToDo">
<table width=300>
<tr><td>
<input type="checkbox" name=checkbox value="001"> 001
</td></tr>
</table>
<input type="submit" name="submit" value="Delete">
</form>
Checking the only available box and clicking the 'Delete' button
gives me a "You must select at least 1 entry" alert.
What am I doing wrong?
Thanks for any pointers,
-Rob