Radio button validation in javascript

 // Add script tag here
  function ValidateForm(form){
  ErrorText= "";
  if ( ( form.gender[0].checked == false ) && ( form.gender[1].checked == false ) ) 
  alert ( "Please choose your Gender: Male or Female" ); 
  return false;
  if (ErrorText= "") { form.submit() }
 // Close script tag here 
 <form name="feedback" action="#" method=post>
     <input type="radio" name="gender" value="Male"> Male
  <input type="radio" name="gender" value="Female"> Female
    <input type="submit" name="SubmitButton" value="Submit" onClick="ValidateForm(this.form)">
 <input type="reset" value="Reset">

2 thoughts on “Radio button validation in javascript

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s