Change the action URL of a form:
document.getElementById("myForm").action = "/action_page.php";
Click button to change the value of the action attribute in the form element.
<!DOCTYPE html> <html> <body> <form id="myForm" action="NotWorking.asp"> 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>/* ww w. j a v a2 s . c o m*/ <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("myForm").action = "/action_page.php"; document.getElementById("demo").innerHTML = "The value of the action attribute was changed."; } </script> </body> </html>
The action
property sets or gets the value of the action attribute in a form.
The action attribute specifies where to send the form data when a form is submitted.
Property Values
Value | Description |
---|---|
URL | Set where to send the form data when the form is submitted. |
The action
property returns a String representing the URL of where to send the form-data when a form is submitted.