Fiddle: http://jsfiddle.net/ugzux/
As you can see, I have a form with a disabled (via javascript) submit button.
I want to be able to bind a click event to it anyway, so I can do some jazzy indication of what needs to be fixed on the input before I'll allow the form to be submitted (i.e enable the button again).
However, disabling the submit button also apparently disables any click events bound to the button, even if they are bound after the disable - any idea how to get around this?
Practically, one solution is to stop disabling the button and instead have an event that does
$('form').submit(function(event){
event.preventDefault();
});
However I want to know the ins and outs of disabled inputs and javascript events, and if there are workarounds as I've never encountered this behaviour before.
Here you go ;)
Just don't disable the button, but prevent submit of the form. Looks like you're trying to validate the form; when you let JS take over the submit action, and return false, the form won't be submit
Making the button
readonly
can help, because the click event will be fired. Though be aware of the differences in behaviour.An other workaround with combination of a required checkbox could be:
CSS-Magic
JQuery-Stuff
Maybe not state of the art, but it works pretty well!
Found this in this question -
I'd thought you might be able to 'fake' a click by wrapping the button in a div and firing the logic on the div's click event. But, as indicated above, the events on disabled elements do not seem to be bubbled up the DOM tree.
You could put a div around the submit button and attach a click function to that for when the submit button is disabled:
This is just code from the top of my head, so it might not be exactly right. But you get the point.