Demo validation of Period button
Click the submit button to validate the form
← Tutorial on Period button Validation
JavaScript
<script type="text/javascript">
function validate(form) {
// Checking if at least one period button is selected. Or not.
if (!document.form1.gender[0].checked && !document.form1.gender[1].checked){
document.getElementById('my_msg').innerHTML="Please select one
radio button before submitting";
return false;}
document.getElementById('my_msg').innerHTML=" Validation is passed,
form is submitted ";
return false; // Validation is passed but form is not submitted.
//return true; // un comment this line to submit the form
}
</script>
HTML
<form name='form1' method=post action=action_page.php onsubmit='return validate(this)'>
<input type=hidden name=todo value=post>
<b>gender</b><input type=radio name=gender value='male'>Male
<input type=radio name=gender value='female'>Female</div>
<div class='col-md-6'>
<div id='my_msg'>Click the submit button to validate the form</div></div>
</div>
<div class='row'>
<div class='col-md-6'>
<input type=submit value=Submit> <input type=reset value=Reset></form></div>
← Tutorial on Period button Validation
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
plus2net.com