Javascript DOM HTML Form action Property get

Introduction

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

var x = document.getElementById("myForm").action;

Click the "Test" button to return the value of the action attribute in the form element.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm" action="/action_page.php">
  First name: <input type="text" name="fname" value="CSS"><br>
  Last name: <input type="text" name="lname" value="HTML"><br>
  <input type="submit" value="Submit">
</form>// w  ww.j av a  2  s .co m
<button onclick="myFunction()">Test</button>

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

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

</body>
</html>



PreviousNext

Related