HTML, Tutorials

When working with forms there are often times it would be really handy to be able to submit the form and depending on the button clicked changed the form action the data is posted to. Normally this has not been possible so we find workarounds.

I recently found the need for this again and come across a HTML attribute called formaction which is amazing for this! This attribute allows you to specify the url to post to which when pressed will override the form action attribute.

For instance take this form, by default when the form is submitted the form will be posted to next.html but if the input with formaction=”alt.html” is pressed then the form is posted to alt.html instead.

<form action="next.html" method="post">

 <p><input type="submit" name="altSubmit" formaction="alt.html" value="Go to Alt"></p>
 <p><input type="submit" name="nextSubmit" value="Go to Next"></p>

It’s worth pointing out this only works on IE 10 and above and the latest Chrome, Firefox etc