Javascript DOM HTML Button formAction Property get

Introduction

Return the URL to send the form-data when a form is submitted:

var x = document.getElementById("myBtn").formAction;

Click the button to return the value of the formaction attribute of the submit button.

The formaction attribute overrides the HTML form's action attribute.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form action="/action_page.php" method="get">
  First name: <input type="text" name="fname" value="CSS"><br>
  Last name: <input type="text" name="lname" value="HTML"><br>
  <button id="myBtn" type="submit" formaction="/action_page2.php">Submit</button>
</form>/*w  ww. java 2  s .  co  m*/

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

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

<script>
function myFunction() {
  var x = document.getElementById("myBtn").formAction;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

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

The formaction attribute sets where to send the form-data when a form is submitted.

This attribute overrides the HTML form's action attribute.

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

The formAction property accepts and returns a String type value.




PreviousNext

Related