The Form object represents an HTML <form> element.
We can access a <form> element via document.getElementById()
:
var x = document.getElementById("myForm");
Click button to get the URL for where to send the form data when the form above is submitted.
<!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>//from w w w . j av a2s. c o 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>