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

type property (button)

Browser support:
Sets or retrieves the type of a button.
With this property you can create the same type of buttons as with the input element, but with a more complex value. The 'submit' and 'reset' values have effect only within a form 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 button.
One of the following values:
button
Default. Command button.
reset
Reset button. The user can reset the contents of a form with this type of button.
submit
Submit button. The user can submit (send to the server) the contents of a form with this type of button.
Default: button.

Example HTML code 1:

This example illustrates the use of the type attribute:
<form>
    <button type="submit">submit</button>
    <button type="reset">reset</button>
</form>
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 GetButtonType () {
            var buttons = document.getElementsByTagName ("button");
            
            for (var i = 0; i<buttons.length; i++) {
                alert ("The " + i + ". button type = " + buttons[i].type);
            }
        }
    </script>
</head>
<body>
    <form>
        <button type="submit">submit</button>
        <button type="reset">reset</button>
    </form>

    <button onclick="GetButtonType ();">Get the type of buttons!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content