Button formMethod attribute
Definition and usage
formMethod
Property to set or return the formmethod attribute value.
The formmethod attribute specifies the HTTP method used to send form data. This attribute overrides the form's method attribute.
The formmethod attribute is only used for buttons with type="submit".
Form data can be sent as URL variables (using method="get") or as HTTP post (using method="post")
Notes on 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 that can be placed 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)
Notes on the "post" method:
- It sends form data as an HTTP post transaction
- Forms submitted using the "post" method cannot be bookmarked
- More robust and secure than "get"
- No size limit
Note:formmethod attribute It is a new attribute of the <button> element in HTML5.
Instance
Example 1
Return the HTTP method used to send form data:
var x = document.getElementById("myBtn").formMethod;
Example 2
Change the method of sending form data:
document.getElementById("myBtn").formMethod = "post";
Example 3
Another example of returning the formMethod attribute:
var x = document.getElementById("myBtn").formMethod;
Syntax
Return the formMethod attribute:
buttonObject.formMethod
Set the formMethod attribute:
buttonObject.formMethod = get|post
attribute value
value | description |
---|---|
get | Attach form data to 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
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | 10.0 | Support | Support | Support |
Related Pages
HTML Reference Manual:HTML <button> formmethod Attribute