Woo! I scored 100 on the Nettuts quiz about the basics of PHP. Give it a shot! via
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.


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.

Green Web Hosting! This site hosted by DreamHost.