Results 1 to 3 of 3

Thread: I want to validate a form only if certain conditions are met

  1. #1
    Join Date
    Mar 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I want to validate a form only if certain conditions are met

    Hi all,

    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'm not sure where to begin. I have all the proper validation code for a basic form. I keep thinking I should be putting the validation function inside an if statement (i.e. if the Yes radio button is checked, validate the form, otherwise don't). But I can't get it to work and I don't think this is the proper way anyways.

    Your thoughts are appreciated!

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    An if statement is in fact how you'll want to do this. But you'll need to post something for us to work with in order for us to help-- your code, or a link to the page, etc.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Mar 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Cool, ok here is a snippet:

    <script type=text/javascript>
    if ( document.getElementById('radio1').checked == true

    {
    function validate_form ()
    {
    if ( document.CeMAT.vorname.value == "" ){
    alert ( "Geben Sie bitte Ihren Vornamen ein" );
    document.CeMAT.vorname.focus();
    document.CeMAT.vorname.select();
    return false;
    }
    if ( document.CeMAT.nachname.value == "" ){
    alert ( "Geben Sie bitte Ihren Nachnamen ein" );
    document.CeMAT.nachname.focus();
    document.CeMAT.nachname.select();
    return false;
    }
    if ( document.CeMAT.firma.value == "" ){
    alert ( "Geben Sie bitte Ihren Firmenname ein" );
    document.CeMAT.firma.focus();
    document.CeMAT.firma.select();
    return false;

    }
    }
    return true;
    }

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •