View Single Post
  #1 (permalink)  
Old May 9th, 2008, 15:02
svennie12 svennie12 is offline
New Member
Join Date: Mar 2008
Location: Canada
Age: 31
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Validate a form only if certain conditions are met

Hi,

Wondering if you can direct me on how to start this. This is an event registration form. If someone clicks Yes I will attend (radio button), then they should proceed to fill out the form (and this form should be validated onsubmit). The other option is for them to click No (radio button), I will not attend. If they choose this, then they should be able to submit without having to complete the form.

I have this code so far, and while I don't get an error on the page, the page does allow me to submit the form without filling out the mandatory fields when the radio button is checked. So something (lots probably) is missing. Help!

Code: Select all
 function check_radio ()
if (document.getElementById('radio1').checked == true)
 {
  function validate_form ()
  {
      if ( document.reg_form.vorname.value == "" ){
               alert ( "Geben Sie bitte Ihren Vornamen ein" );
    document.reg_form.vorname.focus();
    document.reg_form.vorname.select();
    return false;
  }
   if ( document.reg_form.nachname.value == "" ){
               alert ( "Geben Sie bitte Ihren Nachnamen ein" );
    document.reg_form.nachname.focus();
    document.reg_form.nachname.select();
    return false;
  } 
   }
}
}

Last edited by CloudedVision; May 10th, 2008 at 01:03. Reason: Code tags, please
Reply With Quote