|
|
|
PayPal Developer Community >
Forums >
Technical Discussion >
Basic Website Payments >
Setting up a form with check boxes for multiple items
|
|
|
|
|
|
Setting up a form with check boxes for multiple items
|
|
guille_1
Visitor
Posts: 2
Registered: 09-30-2007


Message 1 of 2

Viewed 1,436 times
|

|
|
Hi if anybody can hel with this one I will appreciate it. I have the following code created by a cgi script: <!-- Paypal Button Image --> <input type="image" src=" http://images.paypal.com/images/x-click-but23.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> <!-- BN ID --> <input type="hidden" name="bn" value="BytesInteractive.A+ Download1.3"> <!-- Name of Download Product --> <input type="hidden" name="item_name" value="El Condor Pasa (The Fly Of The Condor )"> <!-- Item Number --> <input type="hidden" name="item_number" value="El Condor Pasa"> <!-- Cost --> <input type="hidden" name="amount" value="1.30"> <!-- Currency --> <input type="hidden" name="currency_code" value="USD"> <!-- Essential Field --> <input type="hidden" name="add" value="1"> </form> This creates a button for a single downloadable song. I want to use the same principal to create a form with twelve songs available for download where the customer can use checkboxes to select multiple songs to buy and download, and bypass the shipping module on the paypal shopping cart. Thank you in advance
|
|
|
|
10-01-2007 07:08 PM
|
|
|
|
|
|
Re: Setting up a form with check boxes for multiple items
[ Edited ]
|
|
PayPal_FrankIb
Moderator
Posts: 13853
Registered: 06-07-2006


Message 2 of 2

Viewed 1,420 times
|

|
|
You would need to modify the basic code in order to get all the information passed to the PayPal server.
You would use something like this example
Or this example below, You pick 10 checkboxes, you can adapt the code to your needs.:
Code: <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Sample Pack 10 flavors Choose 10</title>
<script type="text/javascript">
<!--
function Dollar (val) { // force to valid dollar amount
var str,pos,rnd=0;
if (val < .995) rnd = 1; // for old Netscape browsers
str = escape (val*1.0 + 0.005001 + rnd); // float, round, escape
pos = str.indexOf (".");
if (pos > 0) str = str.substring (rnd, pos + 3);
return str;
}
function ReadForm (obj1, tst) { // process radio and checkbox
var i,j,amt=0,des="",obj,pos,val,tok,tag,
op1a="",op1b="",op2a="",op2b="",itmn="";
var ary = new Array ();
if (obj1.baseamt) amt = obj1.baseamt.value*1.0; // base amount
if (obj1.basedes) des = obj1.basedes.value; // base description
if (obj1.baseon0) op1a = obj1.baseon0.value; // base options
if (obj1.baseos0) op1b = obj1.baseos0.value;
if (obj1.baseon1) op2a = obj1.baseon1.value;
if (obj1.baseos1) op2b = obj1.baseos1.value;
if (obj1.baseitn) itmn = obj1.baseitn.value;
for (i=0; i<obj1.length; i++) { // run entire form
obj = obj1.elements[i]; // a form element
if (obj.type == "checkbox" || // checkboxes
obj.type == "radio") { // and radios
if (obj.checked) { // did user check it—
val = obj.value; // the value of the selection
ary = val.split (" "); // break apart
for (j=0; j<ary.length; j++) { // look at all items
// first we do single character tokens...
if (ary[j].length < 2) continue;
tok = ary[j].substring (0,1); // first character
val = ary[j].substring (1); // get data
if (tok == "@") amt = val * 1.0;
if (tok == "+") amt = amt + val*1.0;
if (tok == "%") amt = amt + (amt * val/100.0);
if (tok == "#") { // record item number
if (obj1.item_number) obj1.item_number.value = val;
ary[j] = ""; // zap this array element
}
}
val = ary.join (" "); // rebuild val with what's left
tag = obj.id.substring (obj.id.length-2); // get flag
if (tag == "1a") op1a = op1a + " " + val;
else if (tag == "1b") op1b = op1b + " " + val;
else if (tag == "2a") op2a = op2a + " " + val;
else if (tag == "2b") op2b = op2b + " " + val;
else if (tag == "3i") itmn = itmn + " " + val;
else if (des.length == 0) des = val;
else des = des + ", " + val;
}
}
}
// Now summarize stuff we just processed, above
if (op1a.length > 0) obj1.on0.value = op1a;
if (op1b.length > 0) obj1.os0.value = op1b;
if (op2a.length > 0) obj1.on1.value = op2a;
if (op2b.length > 0) obj1.os1.value = op2b;
if (itmn.length > 0) obj1.item_number.value = itmn;
obj1.item_name.value = des;
obj1.amount.value = Dollar (amt);
if (obj1.tot) obj1.tot.value = "$" + Dollar (amt);
}
//-->
</script>
</head>
<body>
<!-- This is the FORM to view the cart contents -->
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="viewcart" name="viewcart">
<p>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="display" value="1" />
<input type="hidden" name="business" value="jas22924@aol.com" />
</p>
</form>
<!-- End of view cart FORM -->
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"
onsubmit="this.target='paypal';
return ReadForm(this, true);">
<p>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value="jas22924@aol.com" />
<input type="hidden" name="item_name" value="" />
<input type="hidden" name="amount" value="" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="lc" value="US" />
<input type="hidden" name="on0" value="Flavors">
<input type="hidden" name="os0" >
<input type="hidden" name="baseamt" value="10.00" />
<input type="hidden" name="basedes" value="Sample Pack 10 flavors" />
Sample Pack 10 flavors Choose 10 flavors
<br /><br />
<input type = "checkbox"
onclick = "ReadForm (this.form, false);"
value = "Apple "
name = b1
id = "cb1_1b" />
Cherry
<input type = "checkbox"
onclick = "ReadForm (this.form, false);"
value = "Grape"
id = "cb2_1b" />
Grape
<input type = "checkbox"
onclick = "ReadForm (this.form, false);"
value = "Vanilla"
id = "cb3_1b" />
Vanilla
<input type = "checkbox"
onclick = "ReadForm (this.form, false);"
value = "Orange"
id = "cb4_1b" />
Orange
<input type = "checkbox"
onclick = "ReadForm (this.form, false);"
value = "Strawberry "
id = "cb5_1b" />
Strawberry
<br />
<input type = "checkbox"
onclick = "ReadForm (this.form, false);"
value = "Lime"
id = "cb6_1b" />
Lime
<input type = "checkbox"<input type = "checkbox"
onclick = "ReadForm (this.form, false);"
value = "Checked box 11 "
id = "cb11_1b" />
Check box 11
<input type = "checkbox"
onclick = "ReadForm (this.form, false);"
value = "Checked box 12 "
id = "cb12_1b" />
Check box 12
<input type = "checkbox"
onclick = "ReadForm (this.form, false);"
value = "Checked box 13 "
id = "cb13_1b" />
Check box 13
<input type = "checkbox"
onclick = "ReadForm (this.form, false);"
value = "Checked box 14 "
id = "cb14_1b" />
Check box 14
<input type = "checkbox"
onclick = "ReadForm (this.form, false);"
value = "Checked box 15"
id = "cb15_1b" />
Check box 15
<br />
<input type = "checkbox"
onclick = "ReadForm (this.form, false);"
value = "Checked box 16 "
id = "cb16_1b" />
Check box 16
<input type = "checkbox"
onclick = "ReadForm (this.form, false);"
value = "Checked box 17 "
id = "cb17_1b" />
Check box 17
<input type = "checkbox"
onclick = "ReadForm (this.form, false);"
value = "Checked box 18 "
id = "cb18_1b" />
Check box 18
<input type = "checkbox"
onclick = "ReadForm (this.form, false);"
value = "Checked box 19 "
id = "cb19_1b" />
Check box 19
<input type = "checkbox"
onclick = "ReadForm (this.form, false);"
value = "Checked box 20 "
id = "cb20_1b" />
Check box 20
<br><br><br>
<input type = "button"
value = "Reset Form"
onclick = "this.form.reset ();" />
<!--Item Total >
<input class="nbor" type="text" name="tot" value="$10.00" size ="6" />
-->
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_cart_SM.gif" name="submit" alt="cart add" />
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_viewcart_SM.gif" alt="cart view"
onclick="document.forms.viewcart.target = 'paypal';
document.forms.viewcart.submit ();
return false;" />
</p>
</form>
checkboxchoices
Message Edited by PayPal_FrankIb on 10-08-2007 08:57 AM
Message Edited by PayPal_FrankIb on 10-08-2007 08:58 AM Frank I. PayPal Certified Developer PayPal Merchant Technical Services Analyst http://www.paypaldeveloper.com PayPal, an eBay Company
Give a man a fish, and you feed him for a day. Teach a man to fish and you feed him for a lifetime.
|
|
|
|
10-02-2007 12:13 PM
|
|
|
|
|
|
|