Javascript Essentials Part 5

Submit Once

Disable submit button when user have hit it once to disallow submitting the form again.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="" language="javascript">
	//add function which disables the form upon submit press
	allowSubmit = true;	
	function disableForm() {
		for ( var i = 0; i < document.forms.length ; i++) {
			for ( var j = 0; j < document.forms[i].length ; j++) {
				var formElement = document.forms[i].elements[j]; = '#999999';
				formElement.readOnly = true;	
		var allow = allowSubmit;
		allowSubmit = false;
		return allow;
This is the form:</br>
<form method="post" action="somepage.html" onsubmit="return disableForm();">
<input type="text"/>
<input type="submit" value="Submit Information"/>

Following is the file containing all the above described scripts in example form, ready to use.

Download Form Related All Above Mentioned Scripts