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


Back to 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>Sex</b><input type=radio name=sex value='male'>Male </font><input type=radio name=sex 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.sex[0].checked && !document.form1.sex[1].checked){ 

//alert("Please Select Sex"); 
document.getElementById('my_msg').innerHTML="Select Sex 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>