Input Submit formMethod Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Submit

Description

The formMethod property sets or gets the formmethod attribute of a submit button, which defines the HTTP method for sending form-data to the action URL.

The formmethod attribute overrides the method attribute of the <form> element.

The formmethod attribute is only used for buttons with type="submit".

The form-data can be sent as URL variables with method="get" or as an HTTP post transaction with method="post".

Set the formMethod property with the following Values

Value Description
get Default. Appends the form-data to the URL in name/value pairs: URL?name=value&name=value
post Sends the form-data as an HTTP post transaction

Return Value

A String, representing the HTTP method that is used to submit the form to the server

The following code shows how to check which HTTP method that is used to submit the form to the server:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form target="_blank">
  First name: <input type="text" name="fname" value="Mary"><br>
  Last name: <input type="text" name="lname" value="Bond"><br>
  <input type="submit" id="mySubmit" formaction="#" formmethod="get" value="Submit">
</form>//from  www.  j  a  v a 2 s .c om

<button onclick="myFunction()">Change formmethod</button>

<p id="demo"></p>

<script>
function myFunction() {
    var v = document.getElementById("mySubmit").formMethod;
    document.getElementById("demo").innerHTML = v;
}
</script>

</body>
</html>

Related Tutorials