I have a form, and want to disable/enable its submit button depending on whether the form's input text fields are empty or have had text entered into them.
I think this means having an event handler for the input text fields' keydown
or keypress
events: when it's fired, this event handler should test whether the input text fields contain text, and enable or disable the submit button accordingly.
The change
event looks like it ought to be more useful than the keydown
or keypress
events, except that it isn't fired until the control in question loses the focus, and what good is that: since the user wants to just type something and then click on the submit button, I want an event handler that's fired by text being entered and not only when the control loses focus.
My questions are:
- Are
keydown
and/orkeypress
events fired before or after the corresponding text has been inserted into the input text field? - Are
keydown
and/orkeypress
events cancellable (can you cancel them to prevent the corresponding text from being entered)?
Edit: FYI, the jQuery validation plug-in re-tests form validity on key up.