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

Forms / Two submit buttons 2

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Hello -

I've got a question about setting up a form with two submit buttons that do two different actions. If anyone could help, i would really appreciate it! Thanks in advance for any help you might be able to offer.

Here's the scenario:

I'm modifying an e-store which uses a shopping cart cgi. I don't know a whole lot about the CGI script and don't think modifying it makes sense for this problem. But, the way it is set up, the user goes through an entire page, choosing the amounts they would like of different items and then has to hit a submit button at the bottom to add the items to the cart. Here is the code for the submit button:

<input type=image name=&quot;add_to_cart&quot; src=&quot;add_to_cart.gif&quot; border=0>

Each item has a code which is used to generate the shopping cart information. The code for a particular item might be configured like this:

<input type=text size=2 name=&quot;id=1012LP|description=Railhed / Tarantella LP|price=8.00|shipping=LP|picture=thumbs/jt1012.gif&quot;>

However, these are records which can be bought in multiple formats (LP, CD, CD EP, etc). So, there are often 2 different formats, which I would like to allow the user to quickly add to their shopping cart by adding a &quot;Buy One Now&quot; button. These buttons can each be a submit button with the action add to cart, but the problem is that I have made hidden fields which set the value of each item to 1. So, if i hit submit it will enter the entire forma, therefore adding each item.

The old version of the site (minus this add one to cart function) can be viewed at


Here is an example of the new version that I am having problems with:


I have set a hidden field in the form with each of the formats' order code and the value set to 1. In other words, it is setting the value of the select field that is shown on the old version to 1 in advance for a quick &quot;BUY ONE&quot; feature. But, since there are two hidden fields, each set to a value of 1, pressing the submit key to &quot;add_to_cart&quot; adds one of each format to the shopping cart. I need to know how to fix it so that it only adds the format that the user chooses and either sets the value of the other hidden field to 0 or ignores that field completely. I can't get the field to set to 0 due to the strange name of the field, so i'm thinking something else might be possibl.

The easiest thing to do would be to have two different forms, each with their own submit button. However, this adds a space after the </FORM> tag and messes up the design. It is too tight to do it this way, unfortunately.

Does anyone have any advice about capturing the submit action and alter what gets added to the shopping cart? I've tried a bunch of different methods, but either that pesky unwanted format gets added to the shopping cart as well, or i have error problems.

Thanks!

Bill
 
How about just adding an onClick event to the submit buttons which call a JS function which then assigns whether you add an LP or a CD.

<input type=image name=&quot;add_cd_to_cart&quot; src=&quot;add_to_cart.gif&quot; border=0 onClick=&quot;return addtocart(cd)>


<HTML>
<HEAD>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function addtocart(type) {
if (type == 'cd') {
lp_hidden_field = 0;
cd_hidden_field = 1;
}
else {
lp_hidden_field = 1;
cd_hidden_field = 0;
}
myPage.myForm.submit();
}
</SCRIPT>

Did you try anything like that?? Mise Le Meas,

Mighty :)
 
This is pretty much what i had been hoping to do all along, but since the names of the fields had to be the order string (which contained spaces and odd characters), it was difficult to reference them by name. I then realized I could add an ID, which allowed it to work in IE. Unfortunately, Netscape does not recognize the ID tag (i think - <B>please tell me if anyone knows of a way to reference an item in a form using the ID tag in Netscape</B>).

For Netscape, I had to bite the bullet and use two checkboxes on one form. Depending on which checkbox is checked, the value of the other hidden field is set to 0.It doesn't look as nice with the checkboxes, but at least it works for Netscape users. Still looking for a solution if anyone has one.
 
<SCRIPT>
function submitFunction(i) {
if (i==1) document.theForm.action=
&quot; if (i==2) document.theForm.action=
&quot; if (i==3) document.theForm.action=
&quot; document.theForm.submit()
}
</SCRIPT>

<FORM NAME=&quot;theForm&quot;>
<INPUT TYPE=&quot;button&quot; VALUE=&quot;Submit 1&quot; onClick=&quot;submitFunction(1)&quot;>
<INPUT TYPE=&quot;button&quot; VALUE=&quot;Submit 2&quot; onClick=&quot;submitFunction(2)&quot;>
<INPUT TYPE=&quot;button&quot; VALUE=&quot;Submit 3&quot; onClick=&quot;submitFunction(3)&quot;>
</FORM>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top