Library code snippets

How to disable all elements on a form

You can have your form to be disabled as soon as the user pressed the submit button so that he doesn't accidently submit the form twice. This is the code you can use.

<HTML>
<HEAD>

<script>
	function disableForm(theform) {
		if (document.all || document.getElementById) {
			for (i = 0; i < theform.length; i++) {
			var formElement = theform.elements[i];
				if (true) {
					formElement.disabled = true;
				}
			}
		}
	}
</script>

</HEAD>

<BODY>

	<form method="post" action="http://www.sdfsdf.com" onSubmit="return disableForm(this);">
		<input type="text" name="Text1">
		<input type="submit" name="SubmitButton" value="Submit">
	</form>
	
</BODY>
</HTML>

Comments

  1. 09 Jun 2008 at 07:00
    Thanks

     

     

  2. 14 May 2007 at 17:54
    I would love to know what the
    "if (true) "

    line is testing and where is this documented?

    Many thanks
    Richard







  3. 01 Jan 1999 at 00:00

    This thread is for discussions of How to disable all elements on a form.

Leave a comment

Sign in or Join us (it's free).

Edward Tanguay Edward Tanguay updates his personal web site tanguay.info weekly with code, links, quotes and thoughts on web development. Sign up for the free newsletter.
AddThis

Related podcasts

  • jQuery in ASP.NET

    In this episode Chris Brandsma, Rick Strahl, Dave Ward, Bertrand Le Roy, Scott Koon, and Steven Harman discuss Microsoft's jQuery in ASP.NET announcement.This episode of the Alt.NET Podcast is brought to you by LLBLGen Pro, the most mature O/R mapper and code generator out there.Are you loo...

Events coming up

Want to stay in touch with what's going on? Follow us on twitter!