Form method attribute

Definition and usage

method Set or return the value of the method attribute in the form.

The HTML method attribute specifies how form-data is sent (form-data is sent to the page specified by the action attribute).

See also:

HTML Reference Manual:HTML <form> method Attribute

Instance

Example 1

Change the method used to send form data:

document.getElementById("myForm").method = "post";

Try it yourself

Example 2

Return the method used to send form data:

var x = document.getElementById("myForm").method;

Try it yourself

Syntax

Return the method attribute:

formObject.method

Set the method attribute:

formObject.method = get|post

Attribute value

Value Description
get Attach form data to the URL: URL?name=value&name=value (default).
post Send form data as an HTTP POST transaction.

Technical details

Return value: String value, indicating the HTTP method used to submit the form ("get" or "post").

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 Support Support Support Support

Note:If the method attribute is undefined (default), Chrome, Internet Explorer/Edge, Firefox, and Opera will return "getHowever, Safari does not return any content.