Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting autocomplete on form input with jQuery

I have a form that detects if all the text-fields are valid on each keyup() and focus(); if they're all valid, it will enable the submit button for the user to press. However, if the user fills in one of the text inputs with a browsers autocomplete feature, it prevents the submit button from being enabled.

Is there a way to detect if any of the input has changed regardless of how it's been changed, using jQuery?

like image 255
Ryan Avatar asked Jul 22 '10 23:07

Ryan


3 Answers

You could try using on input to detect text-based changes (except keys like ctrl and shift) in <input>'s.

For example:

$(input).on('input', function() { 
    console.log($(this).val()); 
});
like image 111
cheshireoctopus Avatar answered Oct 04 '22 08:10

cheshireoctopus


The jQuery change event will only fire on blur. The keyup event will fire as you type. Neither fire on clicking an auto-completion option. I am also searching for a way to detect this, but I'm currently going with

$(selector).bind("change keyup",function(){
    //Do something, probably with $(this).val()
});

But it doesn't quite solve the problem...

like image 32
Spycho Avatar answered Oct 04 '22 07:10

Spycho


Myself I used

$(selector).on("change keyup blur input", function() {});

which did the trick in Chrome. input is what made it work for autocomplete.

like image 31
avoliva Avatar answered Oct 04 '22 09:10

avoliva