Web Design and Development Forums

Validate a form only if certain conditions are met

This is a discussion on "Validate a form only if certain conditions are met" within the JavaScript Forum section. This forum, and the thread "Validate a form only if certain conditions are met are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > JavaScript Forum

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old May 9th, 2008, 15:02   #1 (permalink)
New Member
 
Join Date: Mar 2008
Location: Canada
Age: 31
Posts: 2
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
svennie12 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 10th, 2008, 01:08   #2 (permalink)
Nerdy Moderator
 
CloudedVision's Avatar
 
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 520
Blog Entries: 4
Re: Validate a form only if certain conditions are met

First off, the validate_form function is in the middle of another function, which i don't quite understand. secondly, it doesn't appear to be used anywhere in the script.
__________________
Take it easy

Other Road Design

WebForumz Moderator: HTML | Javascript | PHP
CloudedVision is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 10th, 2008, 14:59   #3 (permalink)
Moderator
 
spinal007's Avatar
 
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,609
Blog Entries: 1
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: Validate a form only if certain conditions are met

I haven't read through the entire code, I haven't seen the HTML, so I'm gonna go on under the assumption that you have those under control. The problem is quite simple as far as I can see.

function abc(){ }; defines a function.
abc(); executes the function.

What you're essentially saying in your code is:
Quote:
if radio1 is checked then
remember this function for me and wait until I ask you to run it
But you never call the function.

Just remove "function validate_form ()" and the corresponding braces and the browser will execute your validation code.
__________________
Diego - SEO Consultant London (My Blog | Fight Me)
jQuery: Star Rating - Multiple File Upload - FCKEditor/Codepress
Before we work on artificial intelligence why don't we do something about natural stupidity?
spinal007 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to Validate a HTML Contact Form Xhmtl HTML Forum 2 Dec 9th, 2007 20:11
[SOLVED] Validate Form Class soloam JavaScript Forum 2 Nov 28th, 2007 14:51
Use frames as conditions? Throntel Flash & Multimedia Forum 0 Jan 13th, 2007 22:50
validate form Monie ASP Forum 1 Sep 2nd, 2004 09:06
validate form? Nick JavaScript Forum 10 Aug 31st, 2004 07:47



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 19:12.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59