Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
7
rated 0 times [  10] [ 3]  / answers: 1 / hits: 155423  / 13 Years ago, sun, may 29, 2011, 12:00:00

is there a way to implement a text change event to detect text change on an HTML input text field?
It's possible to simulate these using key events (key press etc), however, it's really not performant and difficult, is there a better way?


More From » html

 Answers
4

When I'm doing something like this I use the onKeyUp event.



<script type=text/javascript>
function bar() {
//do stuff
}
<input type=text name=foo onKeyUp=return bar() />


but if you don't want to use an HTML event you could try to use jQuerys .change() method



$('.target').change(function() {
//do stuff
});


in this example, the input would have to have a class target



if you're going to have multiple text boxes that you want to have done the same thing when their text is changed and you need their data then you could do this:



$('.target').change(function(event) {
//do stuff with the event object as the object that called the method
)};


that way you can use the same code, for multiple text boxes using the same class without having to rewrite any code.


[#91989] Friday, May 27, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dontaemauricioc

Total Points: 456
Total Questions: 84
Total Answers: 99

Location: Puerto Rico
Member since Fri, Oct 14, 2022
2 Years ago
;