thendal
Programmer
- Aug 23, 2000
- 284
Hi all!
Guys i have a problem how can i validate dynamically created chekboxes ,I tried in the following way,
But it alerts only when all the checkboxes not checked ,and if you check other than the first checkbox it still gives a alert box please check the check box ,
I need if the user selects atleast one checkbox it has to submit
How i can over come this please help me
ThanX
<html>
<head>
<title>Checking The Checkbox</title>
<script>
function check(field)
{
var count=0;
for(var x=0; x < field.length; ++x)
{
if(field.elements[x].type == "checkbox"
{
if(!(field.elements[x].checked))
{
alert("Please select a check box"
return false;
}
else
{
document.f1.submit();
return true;
}
}
}
}
</script>
</head>
<body>
<form name=f1>
One <input type=checkbox name=one1 value="one"><br>
Two <input type=checkbox name=one2 value="two"><br>
Three <input type=checkbox name=one3 value="three"><br>
Four <input type=checkbox name=one4 value="Four"><br>
Five <input type=checkbox name=one5 value="five"><br>
<input type=button value=submit onClick=check(this.form);>
</form>
</body>
</html>
Guys i have a problem how can i validate dynamically created chekboxes ,I tried in the following way,
But it alerts only when all the checkboxes not checked ,and if you check other than the first checkbox it still gives a alert box please check the check box ,
I need if the user selects atleast one checkbox it has to submit
How i can over come this please help me
ThanX
<html>
<head>
<title>Checking The Checkbox</title>
<script>
function check(field)
{
var count=0;
for(var x=0; x < field.length; ++x)
{
if(field.elements[x].type == "checkbox"
{
if(!(field.elements[x].checked))
{
alert("Please select a check box"
return false;
}
else
{
document.f1.submit();
return true;
}
}
}
}
</script>
</head>
<body>
<form name=f1>
One <input type=checkbox name=one1 value="one"><br>
Two <input type=checkbox name=one2 value="two"><br>
Three <input type=checkbox name=one3 value="three"><br>
Four <input type=checkbox name=one4 value="Four"><br>
Five <input type=checkbox name=one5 value="five"><br>
<input type=button value=submit onClick=check(this.form);>
</form>
</body>
</html>