button to Submit Forms

Description

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.

  • form - Specifies the form (or forms) with which the button is associated.
  • formaction - Overrides the action attribute on the form element, and specifies a new URL to submit.
  • formenctype - Overrides the enctype attribute on the form element, and specifies the encoding scheme for the form data.
  • formmethod - Overrides the method attribute on the form element.
  • formtarget - Overrides the target attribute on the form element.
  • formnovalidate - Overrides the novalidate attribute on the form to specify whether client-side validation should be performed.

Example

The following code shows how you can apply these attributes to the button element.


<!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/form"
          formmethod="post">Submit Vote</button>
  </form>
</body>
</html>

The code above omitted the action and method attributes from the form element and provided the configuration through the formaction and formmethod attributes on the button element.





















Home »
  HTML CSS »
    HTML »




HTML Introduction
HTML Document
HTML Section
HTML Group Content
HTML Text Marker
HTML Table
HTML Form
HTML Embed