Skip to content

Instantly share code, notes, and snippets.

@carusog
Created December 29, 2012 15:26
Show Gist options
  • Save carusog/4407550 to your computer and use it in GitHub Desktop.
Save carusog/4407550 to your computer and use it in GitHub Desktop.
How to delete default values in input fields on focus while keeping values typed by the user with jQuery
// Detetes default value in input fields but not user inserted text
default_values = {};
$email = $('input#email');
$email.each(function () {
var index = $(this).attr('name');
var value = $(this).val();
default_values[index] = value;
});
$email.focus(function() {
if ($(this).val() === default_values[$(this).attr('name')]) {
$(this).val('');
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment