I would like to know how it is possible to retrieve the default value of an input field after .val() was changed. My markup are different text-inputs with classes .large and .medium and I have a default text value in every field.
What I want to do is, when the user focusin the field the default value disappears. When focusout the field, the default value comes back. Now when the user already typed something in, the field keeps the typed in value even on focusout BUT what I can't get to work is, if the user deletes its typed in text and focusses out the default value should appear again.
My code is:
var $inputs = $('.large, .medium');
var allowSaveVal = true;
$inputs.on('focusin', this, function() {
saveVal = $(this).val();
if (allowSaveVal) $(this).val('');
});
$inputs.on('keydown', this, function() {
allowSaveVal = false;
$(this).css('color', '#000000');
});
$inputs.on('focusout', this, function() {
if($(this).val() == '') $(this).val(saveVal);
if (allowSaveVal) $(this).val(saveVal);
});
Hope my question is clear. Thanks!