Radio button validation in javascript


<html>
  <head>
 // 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 
 </head>
  <body>
 <form name="feedback" action="#" method=post>
   Gender: 
     <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">
  </form> 
  </body>
  </html>
Advertisements

2 thoughts on “Radio button validation in javascript

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s