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?

Charles
  • 50,943
  • 13
  • 104
  • 142
Patrioticcow
  • 26,422
  • 75
  • 217
  • 337
  • flow doesn't stop just because you return false, it would be like saying, `false; alert('continue')`, still gonna alert. – Dave Chen Jun 13 '13 at 03:41
  • 1
    I guess you could [`stop()`](http://stackoverflow.com/a/550583/2344142), but that's just silly – Dave Chen Jun 13 '13 at 03:43

3 Answers3

1
if (Misc.validateForm() !== false) {
    alert('continue');
}
zerkms
  • 249,484
  • 69
  • 436
  • 539
0

You need to

$(document).on('click', '#create_account', function() {
    if(Misc.validateForm() === false){
        return;
    }
    alert('continue');
});
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
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');
}
Rob K
  • 224
  • 1
  • 6
  • 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 – Patrioticcow Jun 13 '13 at 03:46