Click to See Complete Forum and Search --> : Dynamic drop down boxes and paypal
ASPnovice
05-05-2005, 02:25 PM
I'm new to web development so please be patient with me.
I developed ASP and Access based site that I will use to sell apparel. I'm really struggling with making the drop down boxes work on the detail page. I have two boxes: Color and Size and they're being populated dynamically from the db. Here comes the problem: how do I capture the customer's selections and pass it through paypal button to the cart.
Please help me!
Thank you very much.
you would need to check with paypal to see if they have the ability to handle options on the products. otherwise, you may have to set them up as individual products.
phpnovice
05-05-2005, 07:41 PM
how do I capture the customer's selections and pass it through paypal button to the cart.
You would need to use JavaScript to combine the dynamic selections into a single product string that you pass to PayPal through the submit button.
The alternative to that, is to submit the form -- with the dynamic selections already made -- to your ASP code. Then, your ASP code can do the combining and build the PayPal form/button code to send back to the client as a confirmation page before actually going to PayPal. Thus, when the client confirms by clicking THAT button, the single product string will have already been created by your ASP code.
The final option is to use the PayPal API to pass the information directly from your ASP code without having to send a confirmation page.
ASPnovice
05-06-2005, 01:14 AM
Thank you so much for your help but I have couple follow up questions (very, very basic once I imagine):
1. With the Java would that run on any computer regardless of the browser set up i.e. I remember something about being able to diasble running Java in a browser...or is this a different thing?
2. if I were to have a form and then use ASP, how would that work, how/where do I start?
3. Using API, do you mean using PayPal shopping cart on my site and only passing the total to the paypal site?
Thank you again!
phpnovice
05-06-2005, 11:28 AM
1. Yes, that is a problem for the JavaScrpit method. It might be disabled.
2. What do you mean? This should be a simple matter of building a confirmation page that contains the PayPal single-item button form method of interfacing to PayPal.
3. I don't actually know much, if anything about the PayPal API interface. So far, I have only used the single item button form and the Shopping Cart methods of interfacing to PayPal. I'm about to finish up on my first PHP/MySQL Shopping Cart for a client and will be investigating the PayPal API here shortly for that. I currently use the PayPal Shopping Cart for this client.
ASPnovice
05-06-2005, 02:20 PM
Continueing with the question #2:
let me see if I understand it, sorry if I'm a bit slow, it's all new to me: I have two drop downs with the selections being dynamicly populated. In order to capture the selections, should I put the drop downs in a form and then capture somehow the selection from the form and feed it to a second form that has the paypal button? Is that how it would work or you mean to something else?
Do you know of any good tutorials on forms?
Thank you again for your help, I really appreaciate!!!
phpnovice
05-06-2005, 02:54 PM
You'll have one page with the dropdowns. That page will be submitted to a confirmation page which will take the form values and build a new form in the confirmation page. That form will be structured pretty much just like the form PayPal provides when you use their wizard to create the button-click form. For example:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="...your business name...">
<input type="hidden" name="item_name" value="My product">
<input type="hidden" name="item_number" value="123456">
<input type="hidden" name="amount" value="12.29">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="image" name="submit" border="0"
src="https://www.paypal.com/en_US/i/btn/x-click-but23.gif"
alt="Make payments with PayPal - it's fast, free and secure!">
</form>
You would concatenate your two dropdown values, e.g., into the item_name field shown above. You can even make selected fields visible -- but readonly.
ASPnovice
05-06-2005, 03:12 PM
so the customer would make the selections on the detail page and then go to another webpage to click buy button? Is that correct?
Thank you for such a quick response!!!
phpnovice
05-06-2005, 05:25 PM
so the customer would make the selections on the detail page and then go to another webpage to click buy button?
Yes, that is basically the idea. Naturally, it would not be good to couch it in exactly those terms. :D Seems too redundant. ;) So, The dropdowns page would, for example, have a [Buy Now] button and the confirmation page would have a [Confirm] button -- or some such arrangement like that. For example, you can use the confirmation page to display the total cost of the order and ask for a confirmation before going to PayPal.
product + tax + shipping = total
ASPnovice
05-06-2005, 08:58 PM
hmmm...any way of doing this on one page with ASP, let's say using a frame?
If I were to use java.. would you know where I can find a script for that?
Thank you again!!!
phpnovice
05-06-2005, 09:52 PM
You can perform the same scenario on one page -- but a submit is still required between the presentation of the two forms. This is so that your ASP code can get involved in order to perform the concatenation.
If you want JavaScript, then show me the FORM content with the two dropdowns and the text box to receive the concatenation.
ASPnovice
05-06-2005, 11:33 PM
This is what I have so far and I'm trying to have the os0 value that's going to pay pal to reflect the selections of size and color...can you please help me?
<td> <p>
<select name="size" id="size">
<%
While (NOT Size.EOF)
%>
<option value="<%=(Size.Fields.Item("CatSizeCatID").Value)%>" <%If (Not isNull("ProdID")) Then If (CStr(Size.Fields.Item("CatSizeCatID").Value) = CStr("ProdID")) Then Response.Write("SELECTED") : Response.Write("")%> ><%=(Size.Fields.Item("CatSize").Value)%></option>
<%
Size.MoveNext()
Wend
If (Size.CursorType > 0) Then
Size.MoveFirst
Else
Size.Requery
End If
%>
</select>
<select name="color" id="color">
<%
While (NOT AvailColor.EOF)
%>
<option value="<%=(AvailColor.Fields.Item("AvailColorValue").Value)%>"><%=(AvailColor.Fields.Item("AvailColorValue").Value)%></option>
<%
AvailColor.MoveNext()
Wend
If (AvailColor.CursorType > 0) Then
AvailColor.MoveFirst
Else
AvailColor.Requery
End If
%>
</select>
</td></tr><tr>
<td height="32"> </p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="myemail@___.com">
<input type="hidden" name="undefined_quantity" value="1">
<input type="hidden" name="item_name" value=<%=(FrontPage1.Fields.Item("ProdName").Value)%>>
<input type="hidden" name="item_number" value=<%=(FrontPage1.Fields.Item("ProdSKU").Value)%>>
<input type="hidden" name="amount" value=<%=(FrontPage1.Fields.Item("ProdPrice").Value)%>>
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="return" value="http://www.________.com/ppreturn.asp">
<input type="hidden" name="cancel_return" value="http://www.________.com/ppcancel.asp">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<table><tr><td><input type="hidden" name="on0" value="Color">Color</td><td><select name="os0"><option value=<%=(AvailColor.Fields.Item("AvailColorValue").Value)%>>
</td></tr></table><input type="image" src="http://localhost/______/Images/AddToCart.gif" border="0" name="submit" alt="We use PayPal - it's fast, trusted and very secure!">
</form>
</td>
When I paste the paypal button code the page in the design view gets completely screwed up but in a browser looks fine...why is that?
Thank you so much for your help!!!!
phpnovice
05-07-2005, 09:30 AM
I would think that you should not paste code into a design view. Pasting code should go into a code view. But, I don't know what design tool you're working with so it is impossible to say. Plus, I'm probably not even familiar with whatever tool you're using. ;)
Also, with the code shown, it looks like you will have the PayPal form nested inside of your own form. That will not work. At any rate... The following is the basic JavaScript required to perform that function -- but you didn't show the FORM tag for your main form, so I've used the form name of myForm to represent that form:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="
var sel = document.myForm.elements['size'];
if (sel.selectedIndex < 0) {
alert('Size selection is required.');
sel.focus();
return false;
}
this.elements['on0'].value = sel.options[sel.selectedIndex].value + ' ';
var sel = document.myForm.elements['color'];
if (sel.selectedIndex < 0) {
alert('Color selection is required.');
sel.focus();
return false;
}
this.elements['on0'].value += sel.options[sel.selectedIndex].value;
return true;">
There is even a way that you can have your page perform the double submit if JavaScript is disabled but perform only the single submit when JavaScript is available. Thus, the best of both worlds -- yes? :D
ASPnovice
05-08-2005, 11:30 PM
Thank you so much for your help!!! I just tried incorporating it in but the cart is not working, when I click submit I do get the Paypal's cart site but it says "We have a detected a problem with this shopping cart. If the problem persists, please contact the merchant." Here is the code I'm using....what do you think?
</head>
<script type="text/javascript">
<!--
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="
var sel = document.myForm.elements['size'];
if (sel.selectedIndex < 0) {
alert('Size selection is required.');
sel.focus();
return false;
}
this.elements['on0'].value = sel.options[sel.selectedIndex].value + ' ';
var sel = document.myForm.elements['color'];
if (sel.selectedIndex < 0) {
alert('Color selection is required.');
sel.focus();
return false;
}
this.elements['on0'].value += sel.options[sel.selectedIndex].value;
return true;">
//-->
</script>
</head>
<form action="" method="get" name="myForm">
<select name="size" id="size">
<%
While (NOT Size.EOF)
%>
<option value="<%=(Size.Fields.Item("CatSizeCatID").Value)%>" <%If (Not isNull("ProdID")) Then If (CStr(Size.Fields.Item("CatSizeCatID").Value) = CStr("ProdID")) Then Response.Write("SELECTED") : Response.Write("")%>><%=(Size.Fields.Item("CatSize").Value)%></option>
<%
Size.MoveNext()
Wend
If (Size.CursorType > 0) Then
Size.MoveFirst
Else
Size.Requery
End If
%>
</select>
<select name="color" id="color">
<%
While (NOT AvailColor.EOF)
%>
<option value="<%=(AvailColor.Fields.Item("AvailColorValue").Value)%>" <%If (Not isNull("1")) Then If (CStr(AvailColor.Fields.Item("AvailColorValue").Value) = CStr("1")) Then Response.Write("SELECTED") : Response.Write("")%> ><%=(AvailColor.Fields.Item("AvailColorValue").Value)%></option>
<%
AvailColor.MoveNext()
Wend
If (AvailColor.CursorType > 0) Then
AvailColor.MoveFirst
Else
AvailColor.Requery
End If
%>
</select>
</form>
</td></tr><tr>
<td height="32"> </p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" name="form1" target="paypal">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="____@_____.com">
<input type="hidden" name="undefined_quantity" value="1">
<input type="hidden" name="item_name" value=<%=(FrontPage1.Fields.Item("ProdName").Value)%>>
<input type="hidden" name="item_number" value=<%=(FrontPage1.Fields.Item("ProdSKU").Value)%>>
<input type="hidden" name="amount" value=<%=(FrontPage1.Fields.Item("ProdPrice").Value)%>>
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="return" value="http://www.________.com/ppreturn.asp">
<input type="hidden" name="cancel_return" value="http://www.________.com/ppcancel.asp">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="image" src="http://localhost/______/Images/AddToCart.gif" border="0" name="submit" alt="We use PayPal - it's fast, trusted and very secure!">
</form>
Thank you again!
phpnovice
05-09-2005, 09:15 AM
The code I posted does not go in a script block. It is HTML for the BODY section.
If you'll notice, all of the script is imbedded within the FORM tag.
ASPnovice
05-10-2005, 12:34 PM
Gotcha, I will try that tonight. Thank you!