Jump to content

What Am I Missing


wommbatt
 Share

Recommended Posts

ok, so im very very new to javascripting and ive come accross a problem that i dont understandbtw, i have gone thru the javascript tutorial already and from what im reading the following script should work, but it doesntwhat id like it to do is merely require the 2 fields to be filled in in some matter, at this point im not concerned about special characters or min/max length of the field's contentsanother note, the "form action="submit.htm"" is just a temp thing, im also working on that but want a this form to work before i go furtherif someone would be so kind as to tell me where im screwing up and exactly why the script isnt doing what i want it to, id be indebted to u

<html><head><script type="text/javascript">function validate_required(field,alerttxt){with (field)  {  if (value==null||value=="")    {    alert(alerttxt);return false;    }  else    {    return true;    }  }}function validate_form(thisform){with (thisform)  { if (validate_required(email,"Email must be filled out!")==false)  {email.focus();}  return false;}  { if (validate_required(password,"password must be filled out.")==false)  {password.focus();}  return false;}}</script></head><body><form action="submit.htm" onsubmit="return validate_form(this)" method="post">			<label>Email:<input type="text" id="email" name="email" size="30" id="email"></label><br />			<label>Password: <input type="password" id="password" name="password" size="30" value=""> </label><br />			<input type="submit" value="Submit">		</form></body></html>

Link to comment
Share on other sites

You have a few nesting issues - count your brackets*.* Edit: I meant braces.

Edited by Synook
Link to comment
Share on other sites

As Synook said, but I really recommend you to put your brackets in the clearest way. You are now doing something like:

  if (validate_required(email,"Email must be filled out!")==false)  {email.focus();}

Try to do it like this, don't concern yourself about a lot of new lines. In the longer scripts everything will be much easier to read if you do it like below. Use spaces and new lines.if ( validate_required(email, "Email must be filled out!") == false) { email.focus();}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...