- HTML Tutorial
- HTML - Home
- HTML - Introduction
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Headings
- HTML - Paragraphs
- HTML - Fonts
- HTML - Blocks
- HTML - Style Sheet
- HTML - Formatting
- HTML - Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - formaction Attribute
HTML formaction attribute is used to specify an URL of the file that will process the input controls and redirect to a different page when the form is submitted. It overrides the action attribute of the form element. It is used with image and submit type of input elements and also used with <button> elements.
For example, if the image type input element has the formaction attribute present, when the user clicks on an image, it will redirect to a different page. And if the user submits the form, it will redirect to the URL specified in the action attribute of the <form> element.
Syntax
<tag formaction = "URL"></tag>
Applies On
Below listed elements allow using of the HTML formaction attribute
Element | Description |
---|---|
<input> | HTML <input> tag is used to accept textual input from user. |
<button> | HTML <button> tag defines a clickable button in HTML. |
Example of HTML formaction attribute
Bellow examples will illustrate the HTML formaction attribute, where and how we should use this attribute!
Input element with formaction Attribute
In the following example, we are going to use the HTML formaction attribute with input type=submit.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML 'formaction' attribute</title> </head> <body> <p> On clicking login button you will be redirected to index.html page of tutorialspoint as mentioned according to that in action attribute of form tag. </p> <form action="html/index.htm" method="get"> <label for="">Username</label> <input type="text"> <br> <br> <label for="">Password</label> <input type="password"> <br> <br> <input type="submit" value="Login"> </form> <br><br><hr><br> <p> Overriding the link in the action attribute of form tag using formaction attribute of input tag. This form will redirect you to tutorialspoint main page even though link to html page is present in action attribute. </p> <form action="html/index.htm" method="get"> <label for="">Username</label> <input type="text"> <br> <br> <label for="">Password</label> <input type="password"> <br> <br> <input type="submit" value="Login" formaction="https://www.tutorialspoint.com"> </form> </body> </html>
Button element with formaction Attribute
Considering the another scenario, where we are going to use the formaction attribute with the button element.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML 'formaction' attribute</title> </head> <body> <!--HTML 'formaction' attribute--> <p>Example of the HTML 'formaction' attribute</p> <form action="https://www.tutorialspoint.com" method="get"> <label for="">Name</label> <input type="text"> <br> <br> <label for="">Email</label> <input type="email"> <br> <br> <label for="">Mobile</label> <input type="number"> <br> <br> <button>Submit 1</button> <button formaction="/html/index.htm">Submit 2</button> </form> <p> Submit 1 will redirect you home page of tutorialspoint as it's mentioned in action attribute of form tag, while submit 2 will override this using formaction and will submit to html page of tutorialspoint. </p> </body> </html>
Supported Browsers
Attribute | |||||
---|---|---|---|---|---|
formaction | 9.0 | 10.0 | 4.0 | 5.1 | 15.0 |
To Continue Learning Please Login
Login with Google