I have two input fields and i need a function that do something when the value of #name or #email was changed. My start doesn't really work.
$('#name').keyup( function() {
// OR
$('#email').keyup( function() {
// DO SOMETHING
});
});
I have two input fields and i need a function that do something when the value of #name or #email was changed. My start doesn't really work.
$('#name').keyup( function() {
// OR
$('#email').keyup( function() {
// DO SOMETHING
});
});
You can use comma , to separate multiple selectors:
$('#name,#email').keyup( function() {
// DO SOMETHING
});
Your code is nested, the second call to the $('#email') keyup event will be executed only if a keyup event on #name was triggered.
The code should be something like this:
$('#name,#email').keyup( function() {
// DO SOMETHING
});
$('#name,#email').on('keyup', function() {
// DO SOMETHING
});
You are closing the keyup function wrongly which is why not working:
$('#name').keyup( function() {
// OR
}); //closing here
$('#email').keyup( function() {
// DO SOMETHING
});
//}); not here
A better solution for multiple selectors use like @Felix:
$('#name,#email').keyup( function() {
// DO SOMETHING
});