Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use jquery to validate an input field on change?

I have an input field:

<input type="text" name="notifyEmail" id="parametersEmail" value="" size=40 />

I have a chunk of jquery code that works when I hit tab or otherwise leave the field, which calls a validation routine:

$("#parametersEmail").blur(function(event) {
    validateParameterEmail();
});

What I would like to do is run the validateParameterEmail() function whenever the value or content of the input field changes.

So I then also tried the .change() handler:

$("#parametersEmail").change(function(event) {
    validateParameterEmail();
});

But when I change the contents of parametersEmail, this handler does not call the validation function.

Is there another handler I should be using, instead? Or can I not attach multiple event handlers to the input field?

like image 365
Alex Reynolds Avatar asked Feb 01 '11 22:02

Alex Reynolds


1 Answers

Try $("#parametersEmail").keydown(function(event) {})

like image 153
Ish Avatar answered Sep 23 '22 08:09

Ish