- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Why formaction attribute is not working outside of <form> tag?
We can make the formaction attribute to work outside the <form> tag. The formaction attribute is used to specify more than one submit URLs for one form. When you submit a form, the web browser first checks for a formaction attribute.
If the formaction is not present, the web browser moves on to look for an action attribute on the form element.
Here’s an example of the formaction attribute with three different submit buttons −
<!DOCTYPE html> <html> <head> <title>HTML formaction attribute</title> </head> <body> <form method="post"> <input type = "text" name="name"/><br> <button type = "submit" formaction = "btn1.php">Button1</button> <button type = "submit" formaction = "btn2.php">Button2</button> <button type = "submit" formaction = "btn3.php">Button3</button> </form> </body> </html>
Yes, the formaction attribute won’t work outside the form element, but you can still let them work correctly in the following way −
You can easily place the button and use the formaction attribute outside the form, using the associated form id value.
<!DOCTYPE html> <html> <head> <title>HTML formaction attribute</title> </head> <body> <form method="post" id="newForm"> <input type="text" name="name"/> </form> <button type="submit" formaction="btn1.php" form="newForm">Button1</button> <button type="submit" formaction="btn2.php" form="newForm">Button2</button> <button type="submit" formaction="btn3.php" form="newForm">Button3</button> </body> </html>
- How to use formaction attribute in HTML?
- HTML5 <audio> tag not working in Android Webview
- Are button HTML tags outside of a form valid?
- Why <big> is not in HTML 5 Tag list while <small> is?
- HTML Form method Attribute
- HTML Form action Attribute
- Why is cricket not a part of Olympics?
- Callback is not working on remote but working locally in SAP CRM
- Why am I not getting the desired results despite working very hard?
- Working with <polygon> tag in HTML5
- HTML <button> form Attribute
- HTML <form> target Attribute
- HTML <form> autocomplete Attribute
- Working with NULL and IS NOT NULL in MySQL