0

i have the fallowing example:

<input type="button" id="create_account" value="Save">

var Misc = {
    validateForm: function () {
        if(x == 1){
            return false;
        }
        // this is a simplified example, but sometimes x != 1 and there is no return
    }
}

$(document).on('click', '#create_account', function() {
    Misc.validateForm();
    alert('continue');
});

the issue i'm having is that i get continue, even though i return false.

what i would like to happen is to run the alert only if Misc.validateForm(); doesn't return anything

any ideas on this issue?

2
  • flow doesn't stop just because you return false, it would be like saying, false; alert('continue'), still gonna alert. Commented Jun 13, 2013 at 3:41
  • 1
    I guess you could stop(), but that's just silly Commented Jun 13, 2013 at 3:43

3 Answers 3

1
if (Misc.validateForm() !== false) {
    alert('continue');
}
Sign up to request clarification or add additional context in comments.

Comments

0

You need to

$(document).on('click', '#create_account', function() {
    if(Misc.validateForm() === false){
        return;
    }
    alert('continue');
});

Comments

0

Right now you are returning false but that does not determine that execution stops. You should use something along the lines of:

if (!Misc.validateForm()) {
    alert('continue');
}

1 Comment

yes, i figure that much (witch is a bit different), the idea was to use Misc.validateForm() to either stop or continue the script. but thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.