DEMO : Validation of Checkbox and period buttons on submit of a Form

gender Male Female
Submit the form by clicking the button
I agree to terms and conditions


Checkbox validation Checkbox JavaScript

HTML

<form name=form1 method=post action=action_page.php onsubmit='return validate(this)'><input type=hidden name=todo value=post>

<div class='col-md-4'><b>gender</b><input type=radio name=gender value='male'>Male </font><input type=radio name=gender value='female'>Female</div></div>

<div class='row'><div class='col-md-4'><input type=checkbox name=agree value='yes'>I agree to terms and conditions  </div>
<div class='col-md-4'><div id='my_msg'>Submit the form by clicking the button</div></div></div>

<div class='row'><div class='col-md-4'><input type=submit value=Submit> <input type=reset value=Reset></div></div>

</form>

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){ 

//alert("Please Select gender"); 
document.getElementById('my_msg').innerHTML="Select gender by selecting radio buttons before submitting ";
return false;}

if (!document.form1.agree.checked) { 
document.getElementById('my_msg').innerHTML="Agree to Terms & Conditions checkbox before submitting ";
 return false; } 

document.getElementById('my_msg').innerHTML="Validation is complete.";
return false;

}
</script>

Checkbox Validation Validation of dropdown Listbox
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com










    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer