Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery change not firing until blur

Tags:

jquery

I use change(handler) to listen to change events to a textarea, but I only receive an event when the textarea loses focus, but I want to receive an event as soon as the value changes.

$("#text_object").change(listener); function listener(dom){ alert("I'm not getting here before the textarea loses focus"); } 
like image 942
Dude Dawg Avatar asked Apr 22 '12 17:04

Dude Dawg


2 Answers

according to the right answer here Javascript change event on input element fires on only losing focus

you should do something like this

$('#name').on('change textInput input', function () {         }); 

however I found that having both textInput and input events can cause the event to fire twice, you don't want that, so just do

$('#name').on('change input', function () { ...

like image 186
Slim Fadi Avatar answered Sep 30 '22 11:09

Slim Fadi


Unfortunately the browser only recognises a change when the field blurs, so you might want to try attaching a keyup listener. Not the most elegant solution, unfortunately.

Details at http://api.jquery.com/keyup/.

like image 35
Arno Avatar answered Sep 30 '22 09:09

Arno