[Javascript] Replace submit button upon click...

Hassan Schroeder hassan at webtuitive.com
Fri Mar 14 16:55:41 CST 2003


Chris Nafziger wrote:
> In a controlled environment (IE 5+), is it possible have a function, 
> that can be included in any page, that replaces a submit button with the 
> contents of a string, and submits the form, when the button is clicked, 
> without having to specify the onClick event for submit buttons 
> throughout the site.  I'm looking for a little function to put in an ASP 
> include that is included on each page of the site, which will 
> effectively make the text "Pending..." appear, each time a submit button 
> is clicked, with no work involved other than creating the function, and 
> putting it in the include. 

Since you said "controlled" -- srcElement is strictly IE -- try
putting this in the include in the head of your documents:

function init()
{
	allInputs = document.getElementsByTagName("input");
	for ( i = 0; i < allInputs.length; i++ )
	{
		if ( allInputs[i].type == "submit" )
		{
			allInputs[i].onclick = pending;
		}
	}
}
function pending()
{
	var thisButton = window.event.srcElement;
	thisButton.style.borderStyle = "none";
	thisButton.style.borderWidth = "0";
	thisButton.style.backgroundColor = "Window";
	thisButton.value = "Pending...";
}
window.onload=init;

Doesn't *actually* remove the submit button, but fakes it well :-)
And requires no changes to the forms themselves, and works with
forms with multiple submit buttons.

[Tested IE5.5/W2K and IE5.2/OSx -- YMMV, etc. I'd be interested in
  knowing if it works in Win/5.0, if anyone tries it.]

FWIW!
-- 
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com

                           dream.  code.






More information about the Javascript mailing list