Javascript Reference - HTML DOM Input Submit formAction Property








The formAction property sets or gets the formaction attribute of a submit button.

The formaction attribute specifies the URL that will process the form.

The formaction attribute from submit button overides the action attribute of the <form> element.

Browser Support

Input Submit formAction Yes 10.0 Yes Yes Yes

Syntax

Return the formAction property.

var v = submitObject.formAction 

Set the formAction property.

submitObject.formAction=URL




Property Values

Value Description
URL Sets the URL that will process the form

Possible values.

Return Value

A String type value representing the URL for where to send the form-data.

Example

The following code shows how to change the URL for where to send the form-data.


<!DOCTYPE html>
<html>
<body>
<form action="demo_form.asp">
  First name: <input type="text" name="fname" value="abc"><br>
  Last name: <input type="text" name="lname" value="def"><br>
  <input type="submit" id="mySubmit" formaction="demo_admin.asp" value="Submit">
</form><!--from w w  w .ja  v  a2s . co m-->
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    document.getElementById("mySubmit").formAction = "demo_newvalue.asp";
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to get the URL that will process the form.


<!DOCTYPE html>
<html>
<body>
<!-- w  w w. ja v a  2 s.  co m-->
<form action="demo_form.asp">
  First name: <input type="text" name="fname" value="abc"><br>
  <input type="submit" id="mySubmit" formaction="demo_admin.asp" value="Submit">
</form>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("mySubmit").formAction;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: