Created
June 16, 2010 02:15
-
-
Save thumblemonks/440046 to your computer and use it in GitHub Desktop.
input prompt JS
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
<form id="some-form"> | |
<input type="text" id="some-field" value="Fill me in" class="input_prompt" /> | |
<input type="submit" value="Go!" /> | |
</form> |
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
$.input_prompt = function(inputElement) { | |
inputElement.focus(function() { | |
var element = $(this); | |
if (element.data("label") == undefined) { element.data("label", element.attr("defaultValue")); } | |
if (element.data("label") == element.val()) { element.val(""); } | |
}); | |
inputElement.blur(function() { | |
var element = $(this); | |
if (element.val().length == 0) { element.val(element.data("label")); } | |
}); | |
}; | |
$(document).ready(function() { | |
$("input.input_prompt, textarea.input_prompt").each(function(i) { $.input_prompt($(this)); }) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment