Created
December 10, 2010 07:55
-
-
Save pacoguzman/735932 to your computer and use it in GitHub Desktop.
Clear Default for input text fields using prototype 1.7.0
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
/* | |
* Clear Default Text: functions for clearing and replacing default text in | |
* <input> elements. | |
* | |
* by Ross Shannon, http://www.yourhtmlsource.com/ | |
* Migrated to prototype 1.7.0 by @fjguzman | |
*/ | |
document.observe("dom:loaded", function() { | |
function clearDefaultText(e) { | |
if (this.getValue() == this.retrieve('defaultText')) | |
this.writeAttribute('value', "") | |
} | |
function replaceDefaultText(e) { | |
if (this.getValue() == '' && this.retrieve('defaultText')) | |
this.writeAttribute('value', this.retrieve('defaultText')) | |
} | |
$$("input[type='text']").each(function(input, index) { | |
if(!input.hasClassName('cleardefault')) | |
return; | |
input.observe('focus', clearDefaultText).observe('blur', replaceDefaultText); | |
/* Save the current value */ | |
if (input.getValue() != '') | |
input.store('defaultText', input.getValue()) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment