Skip to content

Instantly share code, notes, and snippets.

@thumblemonks
Created June 16, 2010 02:15
Show Gist options
  • Save thumblemonks/440046 to your computer and use it in GitHub Desktop.
Save thumblemonks/440046 to your computer and use it in GitHub Desktop.
input prompt JS
<form id="some-form">
<input type="text" id="some-field" value="Fill me in" class="input_prompt" />
<input type="submit" value="Go!" />
</form>
$.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