PRB: Disabled Form Elements Are Not Submitted (287738)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 4.0
  • Microsoft Internet Explorer (Programming) 4.01
  • Microsoft Internet Explorer (Programming) 4.01 SP1
  • Microsoft Internet Explorer (Programming) 4.01 SP2
  • Microsoft Internet Explorer (Programming) 5
  • Microsoft Internet Explorer (Programming) 5.01
  • Microsoft Internet Explorer (Programming) 5.01 SP1
  • Microsoft Internet Explorer (Programming) 5.5

This article was previously published under Q287738

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.

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.

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.

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>
				

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.

Modification Type:MajorLast Reviewed:5/10/2003
Keywords:kbDHTML kbprb KB287738