Skip to content

Instantly share code, notes, and snippets.

@computercarguy
Created June 26, 2012 17:41
Show Gist options
  • Save computercarguy/2997362 to your computer and use it in GitHub Desktop.
Save computercarguy/2997362 to your computer and use it in GitHub Desktop.
JavaScript to give you the ability to put default text in a text field, then remove it when a user clicks the field, and put that text back in if they leave the field empty.
function Focus(TextboxName,TheValue){
if (document.getElementById(TextboxName).value == TheValue){
document.getElementById(TextboxName).value = "";
} }
function Blur(TextboxName,TheValue){
if (document.getElementById(TextboxName).value == ""){
document.getElementById(TextboxName).value = TheValue;
} }
// usage in X/D/HTML
<input type="text" value="First Name:" name="First" id="First" onfocus="Focus('First','First Name:')" onblur="Blur('First','First Name:')" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment