Need some help with Javascript please! (files provided)

screw3d

Diamond Member
Nov 6, 2001
6,906
1
76
Here are the two files:

newuser.html
validate.js

I'm pretty sure there isn't anything wrong with the syntax - I've validated my HTML and checked the javascript on IE, Firefox and Windows' Script Host.

The whole thing actually works, but there's a weird problem on the "birthdate" section (the last section of the file). The strange thing is, it'll work if I change it to a IF statement, but if it's an ELSE-IF (the way I want it to be), it just wouldn't process the lines! :confused::|

Can someone please tell me what I have overlooked? I've tried everything I can think of.. no go :confused::frown:

Any help appreciated.. thanks!

Edit: BTW you can download the files and it would run nicely on your computer.
 

Softballslug

Senior member
Feb 22, 2000
397
0
0
The problem is the following code:

====================================
else if (document.newuser.phone.value.length==12)
{
blabla
}
else if (document.newuser.phone.value.length==13)
{
blabla
}
// Birthdate
else if (document.newuser.birthdate.value.length<10) // *** this works if it's an IF statement
{
alert("Birth Date is in incorrect format! Please enter mm/dd/yyyy!");
}
=====================================
once an else if is performed the command processor ignores the rest of the else if's... which is why you don't get multiple
alerts on an empty form.

SO, when your code goes in and verifies that the phone format is correct as far as it is concerned it is done because
it has executed an else if..... control is returned to the next statement following the } of the else if that was just done...
 

screw3d

Diamond Member
Nov 6, 2001
6,906
1
76
Originally posted by: Softballslug
The problem is the following code:

====================================
else if (document.newuser.phone.value.length==12)
{
blabla
}
else if (document.newuser.phone.value.length==13)
{
blabla
}
// Birthdate
else if (document.newuser.birthdate.value.length<10) // *** this works if it's an IF statement
{
alert("Birth Date is in incorrect format! Please enter mm/dd/yyyy!");
}
=====================================
once an else if is performed the command processor ignores the rest of the else if's... which is why you don't get multiple
alerts on an empty form.

SO, when your code goes in and verifies that the phone format is correct as far as it is concerned it is done because
it has executed an else if..... control is returned to the next statement following the } of the else if that was just done...
I have a whole bunch of else-if statements above, and what I want is NOT multiple alerts (I would have done multiple IFs, not ELSE-IFs), but only one alert per the first error detected.

The flow goes like this:

Check first field - OK - move to next field - OK - move to next field - detects error! - STOP. Even if there are errors further down below, it wouldn't check it until the first detected error is corrected.

Right now the problem is when there's nothing entered in the birth date field and all other fields before it are correctly entered, it simply won't execute the code that checks the birthdate (it should return an alert). I simply can't see any reason why this should happen! :confused:

More help please?

Edit: Never mind.. I read your reply again and suddenly realized what I did wrong. Thanks a lot!