0

I need to check on clicks while the button is disabled is this possible? Or is there any other way to this?

HTML:

<form id="form">
  <input type="submit" id="submit" value="Submit" />
</form>

JS:

$("#form").submit(function (e) {
    e.preventDefault();
    return false;
    $("#submit").on("click", function () {
        alert("Bla");
    });
});

JS Fiddle: http://jsfiddle.net/hjYeR/1/

3 Answers3

2

When you are using preventDefault(), there is no need to use return false.

However, any code after return statement in a function, won't execute.

Also there is no need to attach an event inside another event, write them separately:

$("#form").submit(function (e) {
    e.preventDefault();
});

$("#submit").on("click", function () {
    alert("Bla");
});

jsFiddle Demo

0

After you return false; the rest of your function will not run. You can bind your click event before returning false and it should work.

JSP64
  • 1,454
  • 1
  • 16
  • 26
0

return statements are the end point in the function, the codes will not proceed ahead of that.

What you can do is simply remove the click event handler from within the submit handler itself.

$("#form").submit(function (e) {

    return false; //e.preventDefault(); is not needed when used return false;

});

$("#submit").on("click", function () {
    alert("Bla");
});
Starx
  • 77,474
  • 47
  • 185
  • 261