Change the value of the formaction attribute of a button:
document.getElementById("myBtn").formAction = "/action_page2.php";
This example contains a form with a submit button that submits the form to "action_page.php":
Click the button to change the value of the formaction attribute of the submit button.
<!DOCTYPE html> <html> <body> <form 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_page.php">Submit form</button> </form>//w w w . j a v a 2 s .co m <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("myBtn").formAction = "/action_page2.php"; document.getElementById("demo").innerHTML = "The value of the formaction attribute was changed."; } </script> </body> </html>