I want to know how to create multiple onfocus
and onblur
for multiple input fields.
I have something like this but when the name field is onfocus
, the email field is onfocus
too. Is there a way to solve this?
$(document).ready(function(){
focusBlur();
});
function focusBlur() {
var formName = document.getElementById('name');
var valueName = 'name';
var formEmail = document.getElementById('email');
var valueEmail = 'email';
formName.onfocus = function() {
if(formName.value == valueName) {
formName.value = '';
}
if(formEmail.value == valueEmail) {
formEmail.value = '';
}
};
formName.onblur = function() {
if(formName.value == '') {
formName.value = valueName;
}
if(formEmail.value == '') {
formEmail.value = valueEmail;
}
};
}