Form method Property
Example
Change the method for sending form data:
document.getElementById("myForm").method = "post";
Try it yourself »
Definition and Usage
The method property sets or returns the value of the method attribute in a form.
The method attribute specifies how to send form-data (the form-data is sent to the page specified in the action attribute).
Browser Support
The method property is supported in all major browsers.
Note: IE, Firefox, Opera and Chrome return "get" even if no method attribute is defined (this is the default value), while Safari returns nothing.
Syntax
Return the method property:
formObject.method
Set the method property:
formObject.method=get|post
Property Values
Value | Description |
---|---|
get | Appends the form-data to the URL: URL?name=value&name=value (this is default) |
post | Sends the form-data as an HTTP post transaction |
Technical Details
Return Value: | A String, representing the HTTP method used to submit the form (either "get" or "post") |
---|
More Examples
Example
Return the method for sending form data:
var x = document.getElementById("myForm").method;
The result of x will be:
get
Try it yourself »
Related Pages
HTML reference: HTML <form> method attribute
Form Object