Form method Property

❮ Form Object

Example

Change the method for sending form data:

document.getElementById("myForm").method = "post";
Try it Yourself »

Description

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

Property
method Yes Yes Yes Yes Yes

Note: Chrome, Internet Explorer/Edge, Firefox, and Opera return "get" 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;
Try it Yourself »

Related Pages

HTML reference: HTML <form> method attribute


❮ Form Object
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.