Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
127
rated 0 times [  129] [ 2]  / answers: 1 / hits: 15476  / 12 Years ago, thu, january 17, 2013, 12:00:00

I have three input fields as below:



 <input type=text name=address id=address/>
<input type=text name=city id=city/>
<input type=text name=country id=country/>


How can i add onChange event to all of these fields at once something like this:



$(select the elements with id address,city,country).bind(change, function() {
//do something
});

More From » jquery

 Answers
37

use , in id selector as @Rory said



OR



add a class to all this and call change function



<input type=text name=address id=address class=className/>
<input type=text name=city id=city class=className/>
<input type=text name=country id=country class=className/>

$('.className').bind(change, function(){
//your stuff
});


HOWEVER



since it is an input field.. i recommend you to use..keyup(), using change you have to click out of the text box to make it fire.



$('.className').keyup(function(){
//your stuff
});

[#80809] Wednesday, January 16, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bobbie

Total Points: 262
Total Questions: 91
Total Answers: 102

Location: Bermuda
Member since Mon, Dec 5, 2022
2 Years ago
;