Multiple Submit Buttons on Forms: Part I

I recently encountered the challenge of including multiple submit buttons on an html form. Wading through the noise on various blogs and help sites was painful. I finally found the following solution that works, and decided to post this little tutorial…

<form name=myFORM type=post action=default.html>

<input type=’submit’ value=’Open Default Site’ onclick=”this.form.target=’_blank’;return true;”>
<input type=’submit’ value=’Open Special Site’ onclick=”myFORM.action=’special.html’; return true;”> </form>

Note that the default action of the form is defined in the first line by:
action=default.html
Both buttons are of type Submit, but they have different values, which reflect what the buttons actually say.

The command in the first button
onclick=”this.form.target=’_blank’;return true;”
instructs it to follow the default action, which is to open default.html in a new window (indicated by target=’_blank’).

The command in the second button
onclick=”myFORM.action=’special.html’; return true;”
instructs it to take on a new action, which is to open special.html

You can keep adding additional submit buttons this way.

Be Sociable, Share!

Leave a Reply

Your email address will not be published. Required fields are marked *