views:

15

answers:

2

Hi all,

I have a personal simple jQuery validation script.

It works when the submit button is clicked and sets up a variable: $errors = false;

Then there are series of if statements that check for textbox values and conditions, and if conditions are not met, variable $errors is set to true.

The script works except for one thing. If all textbox conditions are met (correlating to false $error variable), the script does not send the form. This is how the script ends:

    if ( ($errors = true) ) {
        return false;
    }
    else if ( ($errors != true) ) {
        //nothing
        return true;
}

I've tried removing the return true;, replacing it with return, and nothing worked. Why does it not send the form?!? It's as if it's constantly stuck on the return false; location.

Now, if I comment out return false;, the script shows the errors and sends the form. Obviously we don't want to send the form if there are errors.

Any help would be appreciated,

Thanks! Amit

+2  A: 

For comparison you're supposed to use == which compares not = which assigns. Since you assign it, it always becomes true.

meder
Genius -- thank you. That did the trick.
Amit
naugtur
You guys are too smart.
Amit
+2  A: 

Hi, I think the problem is that it should be

if ( ($errors == true) ) {

instead of

if ( ($errors = true) ) {
Karasutengu
Yes you're right. That's exactly what meder said. Thank you. Fixed :)
Amit