There are so many ways to check the checkbox validation scripts. But in some scenarios we need to check the checkbox's selected or not dynamically, for which the general scenarios are not usefull.
The below javascript code is used for checking the N number of checkbox's dynamically but not calling each and every checkbox name individually.
Javascript example:
<html>
<head>
<script language="javascript">
function ValidateCheckboxForm(checkForm){
var count = 0;
for(var i=0; i< checkForm.length; i++){
if(checkForm[i].checked == true){
count++;
}
}
if(count <= 0){
alert("please select at least one checkbox");
return false;
}
}
</script>
</head>
<body>
<form name="checkform">
<input type="checkbox" name="a" value="a" />A
<input type="checkbox" name="b" value="b" />B
<input type="checkbox" name="c" value="c" />C
<input type="button" name="submitmail" value="Click Here" onclick="javascript:ValidateCheckboxForm(this.form)"/> </form>
</body>
</html>
Here function name is "ValidateCheckboxForm()"
if user did not check even a single check box then an alert message is provided "to check atleast one check box" else it returns true.
No comments:
Post a Comment