PRB: Form Elements Do Not Support a Type Property

ID: Q184762


The information in this article applies to:


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:


<HTML>
<HEAD>
<SCRIPT>
   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);
      }
   }
</SCRIPT>
</HEAD>
<BODY>
   <FORM NAME=oForm>
      <INPUT TYPE=BUTTON VALUE="IsCheckBox" onClick="IsCheckbox()">
      <INPUT TYPE=CHECKBOX>
      <INPUT TYPE=HIDDEN VALUE="hidden">
      <INPUT TYPE=TEXT VALUE="Default">
   </FORM>
</BODY>
</HTML>
 
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.


MORE INFORMATION

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.

<HTML>
<HEAD>
<SCRIPT>
   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>
<BODY>
   <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>
 


REFERENCES

For more information, please see the MSDN Web Workshop:

http://msdn.microsoft.com/workshop/default.asp

Additional query words:


Keywords          : kbcode kbScript kbHTMLObj 
Version           : WINDOWS:3.0,3.01,3.02
Platform          : WINDOWS 
Issue type        : kbprb 

Last Reviewed: May 3, 1999