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.
The best way I've found to do this is to use a "disabled" class to disable the button. You can then catch click events normally in jquery. If
$(this).hasClass('disabled')
, you do your 'jazzy indication' stuff, along withevent.preventDefault();
Once the user has done their thing, you canremoveClass('disabled')
from theinput[type="submit"]
'button'. Easy!You should use .disabled class to style element to look disabled and then handle it as you wish using .hasClass('.disabled') in your JS code. It sould work as long as you didn't put "pointer-events: none;" declaration in your css code for .disabled class