May 27, 2013

Using click event while button is disabled

Xegano’s Question:

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/

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");
});

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!