Change the type of a button to "submit":
document.getElementById("myBtn").type = "submit";
Click the button below to change the type of the "Submit" button above from "button" to "submit".
<!DOCTYPE html> <html> <body> <form id="myForm" action="/action_page.php"> First name: <input type="text" name="fname"><br> Last name: <input type="text" name="lname"><br> <button id="myBtn" type="button" value="Submit">Submit</button> </form>//from w ww . j a v a 2s.co m <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myBtn").type = "submit"; document.getElementById("demo").innerHTML = "The Submit button now works as it should."; } </script> </body> </html>