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!

Adding Items to a Shopping Cart

Status
Not open for further replies.

khurram

IS-IT--Management
Jan 10, 2001
95
CA
I have the following problem:

I have a form that allows a customer to configure a product using drop-down selection boxes. At the bottom, the click 'update' and the price is updated, etc.

Now, I want to add the 'Add to Cart' button but the way the code is currently is as follows:

<CFFORM action=&quot;THIS_PAGE&quot; method=&quot;POST&quot; enablecab=&quot;Yes&quot;>
--selectable options
<INPUT type=&quot;submit&quot; name=&quot;operation&quot; value=&quot;Update Price&quot;>
<INPUT type=&quot;submit&quot; name=&quot;operation&quot; value=&quot;Add to Cart&quot;>
</CFFORM>

The problem is that the CFFORM refers to itself when the customer clicks on update so that the prices are refresed but to get the item added to the shopping cart, I would need the following:

<CFFORM action=&quot;CART.CFM&quot; method=&quot;POST&quot; enablecab=&quot;Yes&quot;>

I tried to put a CFIF statement saying that if the 'update' button is pressed, process CFFORM 'THIS_PAGE' otherwise process CART.CFM

Of course, I got an extroneous </CFFORM> error.

Any suggestions on how to proceed.


 
Khurram, I don't think you can do this with CFFORM within the same page. If I were you I would try a Javascript:

<script language=&quot;Javascript&quot;>
function doAction(form, which) {

if(which==&quot;1&quot;) {
form.action=&quot;<cfoutput>#SCRIPT_NAME#</cfoutput>&quot;;
form.submit();
}
else {
form.action=&quot;cart.cfm&quot;;
form.submit();
}

}
</script>


<form>
<INPUT type=&quot;button&quot; name=&quot;operation&quot; value=&quot;Update Price&quot; onClick=&quot;javascript:doAction(this.form, 1)&quot;>
<INPUT type=&quot;button&quot; name=&quot;operation&quot; value=&quot;Add to Cart&quot; onClick=&quot;javascript:doAction(this.form, 2)&quot;>
</form>

To use this solution, change the CFFORM to FORM. (which is better in my opinion anyway, the Javascript generated by CFFORM is terrible.
Hope this helps...

<webguru>iqof188</webguru>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top