Microsoft KB Archive/184762

{|
 * width="100%"|

PRB: Form Elements Do Not Support a Type Property

 * }

Q184762

-

The information in this article applies to:


 * Microsoft Internet Explorer (Programming) versions 3.0, 3.01, 3.02

-

SYMPTOMS
Internet Explorer 3.x does not support a "type" property on its elements. In Netscape Navigator, "type" returns a string identifying the type of intrinsic element ("check box", "text", and so forth) It's essentially the TYPE attribute of the INPUT tag. Internet Explorer 4.0 does support this to achieve compatibility with Netscape Navigator.

The ability to determine the type of a form element is useful in order to perform processing on all elements of a certain type, for example, on all check boxes.

CAUSE
The versions of Internet Explorer listed above do not support a type property on form elements.

RESOLUTION
In order to generically determine the element being enumerated in the form collection, identify all the elements that could possibly appear within a form, look at their properties, and determine which property is unique. For example, to determine if an element is a check box, the checked property will return true or false in JScript. If the element is not a check box, the checked property will return the special value null.

Here is some HTML code:

   function IsCheckbox {     for (i = 0; i < document.oForm.elements.length; i++) {        cResult = document.oForm.elements[i].checked strIsCheckBox = "Element " + i;

if (cResult != null) {           strIsCheckBox += " is a checkbox"; }        else {           strIsCheckBox += " is not a checkbox"; }

alert(strIsCheckBox); }  }            For a quick look at all the methods and properties supported by the intrinsic objects, take a look at Intrinsc.ocx using a tool like OLEVIEW. The coclasses represent the objects, and the default interfaces that these coclasses support reveals the properties. Hopefully there's something unique about each of the supported classes.

STATUS
All form elements in Internet Explorer 4.0 support a "type" property.

Steps to Reproduce Behavior
The following code demonstrates that Internet Explorer 3.0 does not support a type property on form elements. The same code runs as expected in Netscape Navigator 3.0.

   function ShowTypes {     for (i = 0; i < document.oForm.elements.length; i++) {        alert("Type=" + document.oForm.elements[i].type); }  }

function DoReset {     alert(document.forms[0].name); document.forms[0].reset; } </SCRIPT> </HEAD>  <FORM NAME=oForm> <INPUT TYPE=BUTTON VALUE="Show Types" onClick="ShowTypes"> <INPUT TYPE=BUTTON VALUE="Reset" onClick="DoReset"> <INPUT TYPE=CHECKBOX> <INPUT TYPE=HIDDEN VALUE="hidden"> <INPUT TYPE=TEXT VALUE="Default"> </FORM> </BODY> </HTML>