Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Event Handler for immediate changes in inputs

I'm looking for a (jQuery) Event Handler that is executing a function immediately after a input[type="text"] value changed. The .change jQuery event handler is executing the function after the input[type="text"] looses focus (which may be good for another situation).

keypress / up / down only work when the user types something into an input (not when I'm manipulating it dynamically).

Is there any solution for this?

like image 764
iWeb Avatar asked May 12 '11 19:05

iWeb


People also ask

What event handler should be used to invoke a function on change of text in input field?

Try oninput : Unlike oninput , the onchange event handler is not necessarily called for each alteration to an element's value. Please Note: You also should not use function keyword as your function name.

How do you find the change in input value?

The change() is an inbuilt method in jQuery that is used to detect the change in value of input fields. This method works only on the “<input>, <textarea> and <select>” elements. Parameter: It accepts an optional parameter “function”. Return Value: It returns the element with the modification.

Which input event will you use on an input tag to get notified every time a user focuses on something else?

The HTML DOM event onfocus is triggered whenever an HTML element it is assigned to receives focus from the user. This event is usually used with <input>, <select> and <a> tags.


1 Answers

One thing that I do in cases like this is to bind the same handler to a bunch of events.

$('input').bind("change blur keyup mouseup", function() {
    $(this).css("color", "red"); // or whatever you want to happen
});

See http://api.jquery.com/bind/

like image 99
jimbo Avatar answered Nov 15 '22 00:11

jimbo