
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM Button type Property
The HTML DOM Button type property is associated with the HTML <button> element. The button element by default has type=”submit” i.e clicking on any button on the form will submit the form. The button type property sets or returns the type of button.
Syntax
Following is the syntax for −
Setting the button type property −
buttonObject.type = "submit|button|reset"
Here, the submit|button|reset are button type values. Submit is set by default.
- Submit − Makes the button a submit button.
- Button − Makes a normal clickable button.
- Reset − Makes a reset button that resets the form data.
Example
Let us see an example of the HTML DOM button type property −
<!DOCTYPE html> <html> <body> <form id="Form1" action="/sample.php"> <label>First Name: <input type="text" name="fname"><br><br></label> <label>Surname: <input type="text" name="lname"><br><br></label> <button id="Button1" type="submit">Submit</button> </form> <p>Click the below button below to change the type of the above button from "submit" to "reset".</p> <button onclick="changeType()">CHANGE</button> <p id="Sample"></p> <script> function changeType() { document.getElementById("Button1").type = "reset"; document.getElementById("Sample").innerHTML = "The Submit button is now a reset button"; } </script> </body> </html>
Output
This will produce the following output −
On filling the details and clicking CHANGE −
Now clicking on Submit (which is now reset) −
In the above example −
We have first created two text fields and a button with type “submit” that will submit our data −
<label>First Name: <input type="text" name="fname"><br><br></label> <label>Surname: <input type="text" name="lname"><br><br></label> <button id="Button1" type="submit">Submit</button>
We have then created the CHANGE button that will execute changeType() method on click −
<button onclick="changeType()">CHANGE</button>
The changeType() method gets the button element by using its id and sets its type to reset. Then the message regarding the change is reflected in the paragraph with “Id” sample. Now when you click on the submit button it will reset i.e clear the form data instead of submitting it −
function changeType() { document.getElementById("Button1").type = "reset"; document.getElementById("Sample").innerHTML = "The Submit button is now a reset button"; }
- Related Articles
- HTML DOM Input Button type Property
- HTML DOM Button autofocus Property
- HTML DOM Button disabled Property
- HTML DOM Button name Property
- HTML DOM Button value Property
- HTML DOM Input Button value Property
- HTML DOM Input Button name Property
- HTML DOM Input Button disabled Property
- HTML DOM Input Button form Property
- HTML DOM Ol type Property
- HTML DOM Event type Property
- HTML DOM Object type Property
- HTML DOM Anchor type Property
- HTML DOM Select type Property
- HTML DOM Link type Property
