pap
04-16-2007, 06:58 AM
hi,
i have a doubt. how to check whether atleast one checkbox is checked in a checkbox group?
<html>
<head>
<script language="Java Script" type="text/javascript">
function validate(MYFORM)
{
var ischecked=true;
for(var i=0;i<document.MYFORM.mycheckbox.length;i++)
{
if (!document.MYFORM.mycheckbox[i].checked)
}
alert("select one checkbox");
}
</script>
</head>
<body>
<form name="MYFORM" method="post" onSubmit="validate(this)">
<input type="checkbox" name="mycheckbox" value="1">TEST 1<br>
<input type="checkbox" name="mycheckbox" value="2">TEST 2<br>
<input type="checkbox" name="mycheckbox" value="3">TEST 3<br>
<input type="checkbox" name="mycheckbox" value="4">TEST 4<br>
<input type="checkbox" name="mycheckbox" value="5">TEST 5<br>
<input type="submit" value="SUBMIT" >
</form>
</body>
</html>
this is the code i have written. among 5 check boxes we have to select atleast one checkbox.otherwise while submitting the form it has to show one alert box. otherwise if we checked some check boxes it has to go some other page.can anybody suggest me what is the problem in my code?give me reply its urgent.
thank you,
pap
i have a doubt. how to check whether atleast one checkbox is checked in a checkbox group?
<html>
<head>
<script language="Java Script" type="text/javascript">
function validate(MYFORM)
{
var ischecked=true;
for(var i=0;i<document.MYFORM.mycheckbox.length;i++)
{
if (!document.MYFORM.mycheckbox[i].checked)
}
alert("select one checkbox");
}
</script>
</head>
<body>
<form name="MYFORM" method="post" onSubmit="validate(this)">
<input type="checkbox" name="mycheckbox" value="1">TEST 1<br>
<input type="checkbox" name="mycheckbox" value="2">TEST 2<br>
<input type="checkbox" name="mycheckbox" value="3">TEST 3<br>
<input type="checkbox" name="mycheckbox" value="4">TEST 4<br>
<input type="checkbox" name="mycheckbox" value="5">TEST 5<br>
<input type="submit" value="SUBMIT" >
</form>
</body>
</html>
this is the code i have written. among 5 check boxes we have to select atleast one checkbox.otherwise while submitting the form it has to show one alert box. otherwise if we checked some check boxes it has to go some other page.can anybody suggest me what is the problem in my code?give me reply its urgent.
thank you,
pap