There are three ways you can use button by setting the three different type attribute.
When you set the type attribute of a button to submit , pressing the button will submit the form that contains the button.
This is the default behavior when you have not applied the type attribute.
Submit button have some additional attributes listed as follows.
<!DOCTYPE HTML> <html> <body> <form> <p> <label for="fave">Fruit: <input autofocus id="fave" name="fave" /></label> </p> <p> <label for="name">Name: <input id="name" name="name" /></label> </p> <button type="submit" formaction="http://example.com/" formmethod="post">Submit</button> </form> </body> </html>
If you set the type attribute from a button to reset , pressing the button causes all of the input elements in the form to be reset to their initial state.
There are no additional attributes for reset button.
<!DOCTYPE HTML> <html> <body> <form action="#"> <p> <label for="fave">Fruit: <input autofocus id="fave" name="fave" /></label> </p> <p> <label for="name">Name: <input id="name" name="name" /></label> </p> <button type="submit">Submit</button> <button type="reset">Reset</button> </form> </body> </html>
If you set the type attribute to button , you create a normal button. It has no special meaning and won't do anything when you press it.
<!DOCTYPE HTML> <html> <body> <form action="#"> <p> <label for="fave">Fruit: <input autofocus id="fave" name="fave" /></label> </p> <p> <label for="name">Name: <input id="name" name="name" /></label> </p> <button type="button"> Do <strong>NOT</strong> press this button </button> </form> </body> </html>
<html> <body> <form action="" method="post"> <button type="submit">Submit</button> <br><br> <button type="reset"><b>Clear this form</b> I want to start again</button> <br><br> <button type="button"><img src="http://www.studentsempire.com" alt="submit" /> </button> </form> </body> </html>