Created
December 29, 2012 15:26
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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