Tuesday, March 20, 2012

Check Box Validation In javascript


Your ckname are
name 1
name 2
name 3
name 4
name 5
name 6





<html>
<head>
<script language="javascript">
function validate()
{
var chksob = document.getElementsByName('ckname[]');
var checkchecked = false;
for (var i = 0; i < chksob.length; i++)
{
if (chksob[i].checked)
{
checkchecked = true;
break;
}
}
if (checkchecked == false)
{
alert("Please select at least one Name .");
return false;
}
return true;
}
</script>
</head>
<body>
<form name="form1" onSubmit="return validate()">
Your ckname are <br>
<input type="checkbox" name="ckname[]" value="blue" id="blue"> name 1 <br>
<input type="checkbox" name="ckname[]" value="red" id="red">name 2 <br>
<input type="checkbox" name="ckname[]" value="green" id="green">name 3 <br>
<input type="checkbox" name="ckname[]" value="yellow" id="yellow">name 4 <br>
<input type="checkbox" name="ckname[]" value="voilet" id="voilet">name 5 <br>
<input type="checkbox" name="ckname[]" value="grey" id="grey">name 6 <br>
<br>
<input type="submit" value="submit" name="submit"/>
</form>
</body>
</html>

No comments:

Post a Comment

If you Satisfied , Please Leave a comment