Latest web development tutorials

HTML DOM Form method attribute

Form Object Reference Form Object

Definition and Usage

method property sets or returns the form method attribute values.

method attribute formulate how to send form data (form data submitted to the address specified in the action attribute).

grammar

formObject.method=value

method attribute can have the following values:

描述
get 在 URL 中添加表单数据: URL?name=value&name=value (默认)
post 使用 http post方法提交表单数据


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support method attribute

Note: Internet Explorer if there is no defined method attribute returns "get" (the default), other browsers no return value.


Examples

Examples

Returns form data transmission method:

<html>
<body>

<form id="frm1" action="form_action.html" method="get">
First name: <input type="text" name="fname" value="Donald"><br>
Last name: <input type="text" name="lname" value="Duck"><br>
<input type="submit" value="Submit">
</form>

<script>
document.write(document.getElementById("frm1").method);
</script>

</body>
</html>

Examples of the above output:

get

try it"


Form Object Reference Form Object