Input Submit formMethod Attribute

Definition and Usage

formMethod Sets or returns the value of the formmethod attribute of the submit button.

The HTML formmethod attribute defines the HTTP method used to send form data to the action URL.

The formmethod attribute overrides the <form> element's method attribute.

The formmethod attribute is only used for buttons with type="submit"

Form data can be sent as URL variables (method="get") or as an HTTP post transaction (method="post")

Considerations regarding the "get" method:

  • It attaches form data in the form of name/value pairs to the URL
  • This is very useful for form submissions where users want to bookmark the results
  • The amount of data you can place in the URL is limited (varies by browser), so you cannot be sure that all form data will be transmitted correctly
  • Do not use the "get" method to pass sensitive information! (Passwords or other sensitive information will be displayed in the browser's address bar)

Considerations regarding the "post" method:

  • It sends form data as an HTTP post transaction
  • Forms submitted using the "post" method cannot be added to bookmarks
  • It is more robust and secure than "get"
  • It has no capacity limit

Note:The formmethod attribute is a new attribute of the <input> element with type="submit" in HTML5.

See also:

HTML Reference Manual:HTML <input> formmethod Attribute

Example

Example 1

Find out the HTTP method used to submit the form to the server:

var x = document.getElementById("mySubmit").formMethod;

Try it yourself

Example 2

Change the method used to send form data:

document.getElementById("mySubmit").formMethod = "post";

Try it yourself

Syntax

Return the formMethod attribute:

submitObject.formMethod

Set the formMethod attribute:

submitObject.formMethod = get|post

Attribute value

Value Description
get Default. Attach form data in the form of name/value pairs to the URL: URL?name=value&name=value.
post Send form data as an HTTP post transaction.

Technical Details

Return Value: A string value that indicates the HTTP method used to submit the form to the server.

Browser Support

The numbers in the table indicate the first browser version that fully supports this attribute.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support 10.0 Support Support Support