I wrote this function:
jQuery(document).ready(function() {
jQuery('input[type=text]').each( function(i) {
thisval = jQuery(this).val();
jQuery(this).blur( function() {
if (jQuery(this).val() == '') {
jQuery(this).val(thisval);
}
});
jQuery(this).focus( function() {
if (jQuery(this).val() == thisval) {
jQuery(this).val('');
};
});
});
});
It is designed to get the input value, and then, if the user presses the button without entering a new value, the old value is returned. This works correctly with one of the inputs on the page, but not with the others. However, when I remove the .blur and .focus functions and just use alert (thisval); it warns the name of each input, so something is wrong with my function, but I can’t understand that. Any help?
source
share