You are here: Reference > JavaScript > client-side > HTML DOM > properties > type (input)

type property (input)

Browser support:
Sets or retrieves the type of the input element.

Syntax:

object.type;
You can find the related objects in the Supported by objects section below.
This property is read/write.
HTML page for this property: type

Possible values:

String that sets or retrieves the type of the input element.
One of the following values:
button
The element is a button control. See the input:button element for details.
checkbox
The element is a check box control. See the input:checkbox element for details.
file
The element is a file selector object with a single-line text input control and a browse button. See the input:file element for details.
hidden
The element is a hidden text control. See the input:hidden element for details.
image
The element is an image control. See the input:image element for details.
password
The element is a single-line text input control, except that text is rendered in such a way as to hide the characters. See the input:password element for details.
radio
The element is a radio button control. See the input:radio element for details.
range
The element is a slider control. See the input:range element for details.
reset
The element is a reset button. Clicking on a reset button resets all controls in the form to their initial values. See the input:reset element for details.
search
The element is a single-line text input control with a search history dropdown list. See the input:search element for details.
submit
The element is a submit button. Clicking on a submit button sends the named contents of the form. See the input:submit element for details.
text
Default. The element is a single-line text input control. See the input:text element for details.
Default: text.

Example HTML code 1:

This example illustrates the use of the type attribute:
<input type="text" name="firstname" /><br />
<input type="radio" /><br />
<input type="checkbox" />
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the type property:
<head>
    <script type="text/javascript">
        function GetInputType () {
            var inputs = document.getElementsByTagName ("input");
            
            for (var i = 0; i < inputs.length; i++) {
                alert ("The " + i + ". input type = " + inputs[i].type);
            }
        }
    </script>
</head>
<body>
    <input type="text" name="firstname" /><br />
    <input type="radio" /><br />
    <input type="checkbox" />

    <br />
    <button onclick="GetInputType ();">Get input type!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

External links:

User Contributed Comments

Post Content

Post Content