Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Web
Expertise: Intermediate
Apr 26, 1999

Replace Form Reset Button With an Image

You may already know how to replace the default gray form submit button with an image (see Tip "Replace Form Buttons With Images"), but do you know how to replace the default gray form reset button with an image? You can do this using JavaScript. The idea is to create a function that will loop through each form element on the page and blank it out or return it to its default state. To create a reset image button, just link the image to the script, which should be placed in the head of the page.
 
<script>
function reset() {
	// The number of elements in the form
	var x = document.myForm.elements.length;   
	// Loop through all elements in the form and blank them out
	for (i=0; i<x; i++) {  
		if (document.myForm.elements[i].type == "text" || 
			document.myForm.elements[i].type == "textarea") {
			document.myForm.elements[i].value = "";
		}
		else if (document.myForm.elements[i].type == "select-one") {
			document.myForm.elements[i].selectedIndex = 0;	
		}	
		else if (document.myForm.elements[i].type == "radio" ||
		 		 document.myForm.elements[i].type == "checkbox") {
			document.myForm.elements[i].checked = false;	
		}	
	}
}
</script>
Steve Renaker
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date