My First Approved Script on CodeCanyon.net
Apr, 2010
29

Self Clearing Input Fields With Javascript and Prototype

I wrote this little script to just create some self clearing input fields. Its pretty simple but it does the job.

Updated: A new version of this script can be found on my GitHub Account… its much sleeker and requires nothing to be put on the input fields. Heres a link to my new self clearing input script

First you have the js

//This can go in the main js or whatever...
function clearInput(staticValue, id){
	if($(id).value == staticValue){
		$(id).value = '';
		$(id).observe('blur', function(){
			if($(id).value == ''){
				$(id).value = staticValue;
			}
		});
	}
}

Just make sure you download and include prototype.

Here is a sample of the html!

Each Input field must have a unique ID for this to work. The first argument in the clearInput() function is the static value of the input field.


Post to Twitter Tweet This!

This entry was posted on 04.29.2010 at 4:59 pm and is filed under Code Bin. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Comments

1 Response to “Self Clearing Input Fields With Javascript and Prototype”

04.30.2010 | 6:09 pm

[...] This post was mentioned on Twitter by Sam Napolitano. Sam Napolitano said: New blog post: Self Clearing Input Fields With Javascript and Prototype http://tinyurl.com/38moono [...]

Leave a Reply

Green Web Hosting! This site hosted by DreamHost.