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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiple submit buttons/actions on a single form

Status
Not open for further replies.

jaredc

Programmer
Jun 28, 2002
43
GB
Hi,

I have a situation where I've got a form which has various data input fields. I need to then present the user with various options, e.g.

- submit form
- submit form and open new page
- submit form and open another new page

with the code looking perhaps something like this
Code:
...
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;submitformdetails.asp&quot;> 
<input type=&quot;text&quot; name=&quot;text1&quot;
...
<input type=&quot;text&quot; name=&quot;text8&quot;
<input type=&quot;submit&quot; name=&quot;submit_details&quot;>
<input type=&quot;submit&quot; name=&quot;submit_details_and_open_page_1&quot;>
<input type=&quot;submit&quot; name=&quot;submit_details_and_open_page_2&quot;>
</form>
....

I'm thinking that whichever option is selected I need to submit the data collected to the next asp(submitformdetails.asp), but also perform another action (e.g. include file, or redirect page) dependant upon which button has been clicked.

My problem really is how to achieve this; I've had a number of thoughts including (somehow) using javascript to control the form action dependant on which button clicked or (again, somehow!) detecting which button has been clicked on the &quot;submitformdetails.asp&quot; page.

I hope this makes sense, and if anyone had any thoughts or ideas regarding this I would be delighted to hear them!
 
You give each button a Value=&quot;submit_details&quot; property etc... and then read this from the following asp page to determine your chosen option then act as required.
 
Sorry was v. tired last night that previous reply was useless, I realised today...

Actual answer I think would be to have 3 javascript functions called via the onclick of each submit button. These can then be used to set the values of the input buttons before submitting the form.

eg:
<input type=&quot;submit&quot; name=&quot;submit_details&quot; value=&quot;&quot; onClick=&quot;setSubmitDetails()&quot;>
<input type=&quot;submit&quot; name=&quot;submit_details_and_open_page_1&quot; value=&quot;&quot; onClick=&quot;setSubmitDetailsOpenPage1()&quot;>
<input type=&quot;submit&quot; name=&quot;submit_details_and_open_page_2&quot; value=&quot;&quot; onClick=&quot;setSubmitDetailsOpenPage2()&quot;>

Javascript
==========
function setSubmitDetails()
{
frm.submit_details.value = true;
frm.submit_details_and_open_page_1 = false;
frm.submit_details_and_open_page_2 = false;
frm.submit()
}

etc...

Then you can read which value has been set to true after the form has been submitted and act as you need to from there. Hope that helps.
 
Hi jriley 10,

Thanks for that, and apologies for my late reply! Fortunately/unfortunately (depedning on your viewpiont) my goalposts have now been moved on this one.

I'm able to include a &quot;choose action page&quot; after the initial form has been submitted which has made life considerably easier.

Thanks anyway for your advice which I've mentally noted and I'm sure will crop up in some future guise...

Cheers
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top