tags:

views:

39

answers:

2

What I am looking to do is if a user complete a form it will provide access to a new location.

<script language="JavaScript" type="text/javascript">     
<!--     
function validateForm(theForm) {     
 var firstname = theForm.firstname.value; 
 var lastname = theForm.lastname.value;      
 var email = theForm.email.value;     
 if (firstname == "") {     
   alert("Please fill in your First Name.");     
   theForm.firstname.focus();     
   return false;     
 }   
 if (lastname == "") {     
   alert("Please fill in your Last Name.");     
   theForm.lastname.focus();     
   return false;     
 } 

 if (email == "") {     
   alert("Please fill in your email address.");     
   theForm.email.focus();     
   return false;     
 }     
 return true;     
}

I know this part is wrong but I have no idea how to go about doing it. any help would be nice..

 if lastname=""
 if firstname=""
 if email=""
 load('www.google.com');
A: 
if (validateForm(theForm)) window.location = 'http://www.google.com';

Is equivalent to using

if (validateForm(theForm)) window.location.href = 'http://www.google.com';

Both will work, so choose which one you prefer.

James Westgate
The way I have it now the user is required to key some sort of data placed in the input boxes.... or does it matter?
Michael
OK, I will change my code to include that
James Westgate
Thanks... I Appreciate the help.
Michael
A: 
if lastname=""
if firstname=""
if email=""
load('www.google.com');

becomes

if ((lastname == "") && (firstname == "") && (email == "")) {
    window.location = "http://www.google.com";
}
GlenCrawford
The parentheses around `lastname == ""` (etc) are unnecessary.
cletus
@cletus But not incorrect. Wrapping each section of the condition in parentheses arguably makes the code more readable.
GlenCrawford
@Rose I disagree. Unnecessary parentheses sometimes make the code more unreadable. Someone reading that sees the parentheses and then has to ask "why are they there?", reading it again to see if they've missed something. But you're right in that it's legal code.
cletus
@cletus/Rose: I'd call this one a matter of opinion. To some extent I guess it depends on what kind of coding style you prefer and/or are used to reading. (Personally I think the parentheses do make the code clearer but it's also perfectly readable without them... but that's me)
David Zaslavsky