Re: Form verification stumped

by Andrej Kostresevic <temporalassassin(at)yahoo.com>

 Date:  Thu, 17 May 2001 18:04:47 -0700 (PDT)
 To:  Chuck Evans <chuck.evans(at)click2learn.com>,
"'HWG Languages'" <hwg-languages(at)hwg.org>
 In-Reply-To:  asymetrix
  todo: View Thread, Original
I didnt have time to thoroughly examine your code, but this is what i did
notice:

> if ( name_of_list == "" ) { 
> 	alert(msg_1); 
> 	}

You are checking to see whether the value is an empty string, not null.
Try either this:

> if ( name_of_list == "" || name_of_list == null) { 
> 	alert(msg_1); 
> 	}

Or even better:

> if ( (name_of_list+"") == "") { 
> 	alert(msg_1); 
> 	}

This will concatenate null with "" therefore making it "". If it is not
null, it will not be changed. 
Hope it helps,:)
Andrej 


--- Chuck Evans <chuck.evans(at)click2learn.com> wrote:
> This should work, but doesn't. That means I'm missing something
> important,
> but I am not a JavaScript expert. What I want to do is have a simple
> form
> that lets someone sign up for an email list (one of three). I can't get
> the
> javascript verification to check if the first element, a radio button
> value,
> is null or not, and the second and third elements don't work either.
> Grrrr.
> Here's the javascript code and the form. Any help is greatly
> appreciated. 
> 
> <script language="JavaScript" type="text/javascript">
> 
> var name_of_list = "";
> var email_one = "";
> var email_two = "";
> 
> function verify_email() {
> 
> var msg_1 = "Please Choose an Email List, Then Resubmit.";
> var msg_2 = "Please Input Your Email Address in Both Boxes.";
> var msg_3 = "The Two Email Addresses Are Not Identical.\nPlease Correct
> and
> Resubmit.";
> 
> var name_of_list = document.get_email.listname;
> var email_one = document.get_email.email_1;
> var email_two = document.get_email.email_2;
> 
> if ( name_of_list == "" ) { 
> 	alert(msg_1); 
> 	}
> 	
> if ( ( email_one == "" ) || ( email_two == "" ) ) {
> 	alert(msg_2);
> 	}
> 
> if ( email_one != email_two ) { 
> 	alert(msg_3); 
> 	}
> 	
> return false;
> 	
> }
> 
> </script>
> 
> <form 
> name="get_email"
> onSubmit=" return verify_email(); "
> action="/cgi-bin/join_mailing_list.pl" 
> method="POST" 
> >
> 
> <p><input type="radio" name="listname" value="investor relations">
> Investor
> Relations
> <br><input type="radio" name="listname" value="product news"> Product
> News
> <br><input type="radio" name="listname" value="press releases"> Press
> Releases</p>
> 
> <p>Email Address: <input type="text" name="email_1" size="20"
> maxlength="50">
> <br>Enter Email Again: <input type="text" name="email_2" size="20"
> maxlength="50"></p>
> 
> <p><input type="Submit" value="Subscribe"></p>
> 
> </form>
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA