Javascript Essentials Part 5
by Hiroshi on November 2nd, 2008
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"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<html>
<body>
<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];
formElement.style.color = '#999999';
formElement.readOnly = true;
}
}
var allow = allowSubmit;
allowSubmit = false;
return allow;
}
</script>
This is the form:</br>
<form method="post" action="somepage.html" onsubmit="return disableForm();">
<input type="text"/>
<input type="submit" value="Submit Information"/>
</form>
</body>
</html>Following is the file containing all the above described scripts in example form, ready to use.
Download Form Related All Above Mentioned Scripts
Related Posts
advertisements
