I’m trying to get my <input.../> fields to go blank on focus, and if on focus out they’re still blank, revert them to their original values.
I would’ve thought this would work, but apparently not:
$('input').focus( function() {
var init_value = $(this).val();
$(this).val('');
});
$('input').focusout( function() {
var new_value = $(this).val();
if(new_value == "") {
$(this).val(init_value);
}
});
Any alterations/advice to get it working would be most appreciated ;)!
You should consider using the HTML5
placeholderattribute as a first option.http://diveintohtml5.ep.io/forms.html#placeholder
With jQuery, you could modify your original script like this:
Example: http://jsfiddle.net/jasongennaro/8bJcQ/
EDIT
Here is a revised script to deal with the situation as mentioned in your comment:
Example 2: http://jsfiddle.net/jasongennaro/8bJcQ/3/