...

View Full Version : Javascript : Loop passing



user7272
07-22-2010, 07:24 PM
i,

Am developing a webform using PL/SQL.

Am using javascript to do some form validation

Sample

if(a =="")
{

alert("Please enter the first name");
return false;


}


else if(b =="")
{


alert("Please enter the last name");
return false;


}

else if (y !="Test1")


{
if (y != "Test2")


{


if (y != "Test3")


{
alert("Enter the right text");
return false;


}
}
alert("am wrong outside");

}


else if(z =="")


{


alert("Please fill al the fields");
return false;


}

it passes till alter("am wrong outside") and executes the procedure but doesnt goes to the last else part.

I want it to go the last else part too.

Please help.

Rowsdower!
07-22-2010, 11:30 PM
i,

Am developing a webform using PL/SQL.

Am using javascript to do some form validation

Sample
...

it passes till alter("am wrong outside") and executes the procedure but doesnt goes to the last else part.

I want it to go the last else part too.

Please help.
That is the nature of the "else if" statement. If it finds one it skips the rest (which makes your "return false;" code superfluous in all but one of those places). For example, this code would function exactly the same as what you already have:

if(a ==""){
alert("Please enter the first name");
}
else if(b ==""){
alert("Please enter the last name");
}
else if (y !="Test1"){
if (y != "Test2"){
if (y != "Test3"){
alert("Enter the right text");
return false;
}
}
alert("am wrong outside");
}
else if(z ==""){
alert("Please fill al the fields");
}

If you wanted to run the last check, irrespective of any alert messages already received, you would want a simple "if" for the last one, rather than the "else if" that you have:

if(a ==""){
alert("Please enter the first name");
}
else if(b ==""){
alert("Please enter the last name");
}
else if (y !="Test1"){
if (y != "Test2"){
if (y != "Test3"){
alert("Enter the right text");
return false;
}
}
alert("am wrong outside");
}
if(z ==""){
alert("Please fill al the fields");
}

user7272
07-23-2010, 11:35 AM
Thanks a lot dude.

It worked!!!!!!.

Philip M
07-23-2010, 06:08 PM
Validation of the form if(a ==""){ is barely worthy of the name, and virtually useless, as even a single space, an x or a ? will return false, that is pass the validation. Numeric values such as zip codes and phone numbers should be validated as such. This topic has been covered many times before in this forum.


It is your responsibility to die() if necessary….. - PHP Manual



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum