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

Back to Checkbox validation | Checkbox | JavaScript


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



<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;