jQuery Radio Button Validation Example
<!DOCTYPE html>
<html>
<head>
<title>Radio</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#button").click(function(){
if($("#radio1").is(":checked")==false && $("#radio2").is(":checked")==false){
alert("Select Gender");
return false;
}
});
});
</script>
</head>
<body>
<form id="form">
<input type="radio" id="radio1" name="radio" value="Male">Male
<input type="radio" id="radio2" name="radio" value="Female">Female<br>
<input type="submit" id="button" value="Submit">
</form>
</body>
</html>
<html>
<head>
<title>Radio</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#button").click(function(){
if($("#radio1").is(":checked")==false && $("#radio2").is(":checked")==false){
alert("Select Gender");
return false;
}
});
});
</script>
</head>
<body>
<form id="form">
<input type="radio" id="radio1" name="radio" value="Male">Male
<input type="radio" id="radio2" name="radio" value="Female">Female<br>
<input type="submit" id="button" value="Submit">
</form>
</body>
</html>
Comments
Post a Comment