Javascript examples for DOM HTML Element:Button
The formAction property sets or gets the formaction attribute of a button, which sets where to send the form-data when a form is submitted.
This attribute overrides the HTML form's action attribute, which is only used for buttons with type="submit".
Set the formAction property with the following Values
Value | Description |
---|---|
URL | Sets where to send the form-data. |
A String, representing the URL for where to send the form-data
The following code shows how to return the URL for where to send the form-data when a form is submitted:
<!DOCTYPE html> <html> <body> <form action="#" method="get"> First name: <input type="text" name="fname" value="Mary"><br> Last name: <input type="text" name="lname" value="Bond"><br> <button type="submit">Submit</button><br> <button id="myBtn" type="submit" formaction="/action_page2.php">Submit to another page</button> </form>/*from w w w .j a va2 s . c om*/ <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myBtn").formAction; document.getElementById("demo").innerHTML = x; } </script> </body> </html>