Button formAction Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Button


The formAction property sets or gets the formaction attribute of a button, which sets where to send the form-data when a form is submitted.

This attribute overrides the HTML form's action attribute, which is only used for buttons with type="submit".

Set the formAction property with the following Values

Value Description
URL Sets where to send the form-data.

Return Value

A String, representing the URL for where to send the form-data

The following code shows how to return the URL for where to send the form-data when a form is submitted:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<form action="#" method="get">
First name: <input type="text" name="fname" value="Mary"><br>
Last name: <input type="text" name="lname" value="Bond"><br>
<button type="submit">Submit</button><br>
<button id="myBtn" type="submit" formaction="/action_page2.php">Submit to another page</button>
</form>/*from   w  w  w .j a  va2 s .  c  om*/

<button onclick="myFunction()">Test</button>

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

function myFunction() {
    var x = document.getElementById("myBtn").formAction;
    document.getElementById("demo").innerHTML = x;


Related Tutorials