Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Command Buttons Inside Form

Status
Not open for further replies.

jakeisstoked

Technical User
May 9, 2003
28
AU
Hi, first off, ive posted a few questions before and got great answers so thanks for that.

My problem: i need to different command buttons on a form, on the posts the data to one page, and one that posts the data to another page, but the "post" is in form tags, so any "submit" uinside the button will post to the page in the "post" action. I need one button to post data to "save1.asp" and the other butotn to post the same data to "save2.asp".

I was thinking there may also be a way to post a querystring with a form but i can't figure that out either, i would need a regular href link to post the form data instead of a command button for that to work.

Any suggestions?
Thanks,
Jake
 
Hi jake,

There are several ways to do this but the one I have used most often is this:
Code:
<input type=&quot;Submit&quot; name=&quot;Choice1&quot; value=&quot;Choice1&quot;>
<input type=&quot;submit&quot; name=&quot;Choice2&quot; value=&quot;Choice2&quot; onClick=&quot;return doChoice();&quot;>

<script language=&quot;javascript&quot;>
function doChoice()
{
document.all.MyFormName.action = 'choice2.asp';
return true
}
</script>

so what this does is when &quot;Choice2&quot; is clicked the javascript changes the action of the form to the new page just before submitting it. If you also had form validation that could block a submit it would be a good idea to set the form action page when you click either choice, otherwise things may get confused if a use clicks &quot;Choice2&quot; the form doesn't submit and then clicks &quot;Choice1&quot; it will still be pointing to &quot;Choice2&quot;'s action page (messy).

You can have as many choices as you want with this method.

I hope it helps.



Travis Hawkins
BeachBum Software
travis@cfm2asp.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top