Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

PRB: Disabled Form Elements Are Not Submitted


View products that this article applies to.

This article was previously published under Q287738

↑ Back to the top


Symptoms

When you submit an HTML form that contains disabled elements, the disabled elements are not submitted with the rest of the form elements. In addition, in your server-side form processing code, you may not receive name/value pairs for any disabled elements that are located on your form.

↑ Back to the top


Cause

According to the World Wide Web Consortium (W3C) HTML specifications, disabled elements cannot be considered "successful", and only "successful" elements are submitted with a form.

↑ Back to the top


Resolution

To submit the values of disabled elements, you must either enable the disabled elements or programmatically create new elements with the same name that submit the values of the disabled element.

↑ Back to the top


More information

The following sample code illustrates how to programmatically create new elements to submit the values of disabled elements through script in Internet Explorer 5.0 or later:
<HTML>
<BODY>
<SCRIPT LANGUAGE="JScript">
function doSubmit(theForm)
{
	var i = 0;
	for (i = 0; i < theForm.elements.length; i++)
	{
		if (theForm.elements[i].tagName == "INPUT" && 
theForm.elements[i].type == "text")
		{
			if (theForm.elements[i].disabled == true)
			{	
				var newElement;
				newElement = document.createElement("INPUT");
				newElement.type = "hidden";
				newElement.name = theForm.elements[i].name;
				newElement.value = theForm.elements[i].value;
				theForm.appendChild(newElement);
				newElement = null;
			}
		}
	}

	return true;
}
</SCRIPT>

<FORM onSubmit="doSubmit(this);" ACTION="formprocessing.asp" METHOD="POST">
 <P>First Name: <INPUT TYPE="TEXT" ID="firstname" NAME="firstname" VALUE="dan">
 <P>Last name:  <INPUT TYPE="TEXT" ID="lastname" NAME="lastname" VALUE="m" DISABLED>
 <P><INPUT TYPE="SUBMIT" VALUE="Submit">
</FORM>

</BODY>
</HTML>
				

↑ Back to the top


References

For more information, see sections 17.12.1 and 17.13.2 of the HTML 4.0 Specification from the following W3C Web site: For more information on the createElement method, see the following Microsoft Web site: For more information on the appendChild method, see the following Microsoft Web site: For more information on the onsubmit event, see the following Microsoft Web site: Microsoft provides third-party contact information to help you find technical support. This contact information may change without notice. Microsoft does not guarantee the accuracy of this third-party contact information.

↑ Back to the top


Keywords: KB287738, kbprb, kbdhtml

↑ Back to the top

Article Info
Article ID : 287738
Revision : 2
Created on : 5/10/2003
Published on : 5/10/2003
Exists online : False
Views : 468