html - Paypal (Option + Value) -
i have simple paypal question.
how make button add 100 usd (example) , random name purchase.
this html might help
<select name="t-shirt blablabla"> <option>do not add</option> <option value="100">do add</option> </select>
you use script modify amount, based on user selection. depending on how simple wanted keep it, create drop down menu, , have menu set price. otherwise if going have different options modify amount, need use script. below example have used in past different selections modify amount.
<!-- start of script --> <script type="text/javascript"> <!-- // function dollar (val) { // force valid dollar amount var str,pos,rnd=0; if (val < .995) rnd = 1; // 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; } var amt,des,obj,val,op1a,op1b,op2a,op2b,itmn; function chktok (obj1) { var j,tok,ary=new array (); // parse ary = val.split (" "); // break apart (j=0; j<ary.length; j++) { // @ items // first single character tokens... if (ary[j].length < 2) continue; tok = ary[j].substring (0,1); // first character val = ary[j].substring (1); // data if (tok == "@") amt = val * 1.0; if (tok == "+") amt = amt + val*1.0; if (tok == "%") amt = amt + (amt * val/100.0); if (tok == "-") amt = amt - val*1.0; if (tok == "#") { // record item number if (obj1.item_number) obj1.item_number.value = val; ary[j] = ""; // zap array element } // 3-character tokens... if (ary[j].length < 4) continue; tok = ary[j].substring (0,3); // first 3 chars val = ary[j].substring (3); // data if (tok == "s1=") { // value shipping if (obj1.shipping) obj1.shipping.value = val; ary[j] = ""; // clear out } if (tok == "s2=") { // value shipping2 if (obj1.shipping2) obj1.shipping2.value = val; ary[j] = ""; // clear out } } val = ary.join (" "); // rebuild val what's left } function storval () { var tag; tag = obj.name.substring (obj.name.length-2); // 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; } function readform (obj1, tst) { // read user form var i,j,pos; amt=0;des="";op1a="";op1b="";op2a="";op2b="";itmn=""; 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; (i=0; i<obj1.length; i++) { // run entire form obj = obj1.elements[i]; // form element if (obj.type == "select-one") { // selects if (obj.name == "quantity" || obj.name == "amount") continue; pos = obj.selectedindex; // option selected val = obj.options[pos].value; // selected value chktok (obj1); // check specials if (obj.name == "on0" || // let go wants obj.name == "os0" || obj.name == "on1" || obj.name == "os1") continue; storval (); } else if (obj.type == "checkbox" || // checkboxex obj.type == "radio") { // , radios if (obj.checked) { val = obj.value; // value of selection chktok (obj1); storval (); } } else if (obj.type == "select-multiple") { //one or more (j=0; j<obj.options.length; j++) { // run options if (obj.options[j].selected) { val = obj.options[j].value; // selected value (default) chktok (obj1); storval (); } } } else if ((obj.type == "text" || // read text, obj.type == "textarea") && obj.name != "tot" && // not here obj.name != "quantity") { val = obj.value; // data if (val == "" && tst) { // force entry alert ("enter data " + obj.name); return false; } storval (); } } // summarize stuff 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> <!-- end of script --> insulin pump pouch - base price $29.95 <form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="this.target = '_self'; return readform(this, true);"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="add" value="1"> <input type="hidden" name="business" value="xxxxxx@ccaples.com"><!--your email address goes here --> <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="bn" value="pp-shopcartbf"> <input type="hidden" name="shopping_url" value="http://ccaples.com/index.php/basic-scripts/examples-ii/cart-button-w-options"> <input type="hidden" name="cancel_return" value="http://ccaples.com/index.php/basic-scripts/examples-ii/cart-button-w-options"> <input type="hidden" name="return" value="http://ccaples.com/index.php/basic-scripts/examples-ii/cart-button-w-options"> <input type="hidden" name="baseamt" value="00"> <input type="hidden" name="basedes" value="insulin pump pouch"> <input type="hidden" name="baseon0" value=""> <input type="hidden" name="baseos0" value=""> <input type="hidden" name="baseon1" value=""> <input type="hidden" name="baseos1" value=""> <input type="hidden" name="baseitn" value=""> <input type="hidden" name="on0" value=""> <input type="hidden" name="os0" value=""> <input type="hidden" name="on1" value=""> <input type="hidden" name="os1" value=""> <input type="hidden" name="item_number" value=""> waist measurement: <select name="size" onchange="readform (this.form, false);"> <option value="please choose" selected>please choose</option> <option value="18 inch waist @29.95">18 inch waist - $29.95</option> <option value="19 inch waist @29.95">19 inch waist - $29.95</option> <option value="20 inch waist @29.95">20 inch waist - $29.95</option> <option value="21 inch waist @29.95">21 inch waist - $29.95</option> <option value="22 inch waist @29.95">22 inch waist - $29.95</option> <option value="23 inch waist @29.95">23 inch waist - $29.95</option> <option value="24 inch waist @29.95">24 inch waist - $29.95</option> <option value="25 inch waist @29.95">25 inch waist - $29.95</option> <option value="26 inch waist @29.95">26 inch waist - $29.95</option> <option value="27 inch waist @29.95">27 inch waist - $29.95</option> <option value="28 inch waist @29.95">28 inch waist - $29.95</option> <option value="29 inch waist @29.95">29 inch waist - $29.95</option> <option value="30 inch waist @29.95">30 inch waist - $29.95</option> <option value="31 inch waist @29.95">31 inch waist - $29.95</option> <option value="32 inch waist @29.95">32 inch waist - $29.95</option> <option value="32 inch waist @29.95">32 inch waist - $29.95</option> <option value="33 inch waist @30.95">33 inch waist - $30.95</option> <option value="34 inch waist @30.95">34 inch waist - $30.95</option> <option value="35 inch waist @30.95">35 inch waist - $30.95</option> <option value="36 inch waist @30.95">36 inch waist - $30.95</option> <option value="37 inch waist @30.95">37 inch waist - $30.95</option> <option value="38 inch waist @31.95">38 inch waist - $31.95</option> <option value="39 inch waist @31.95">39 inch waist - $31.95</option> <option value="40 inch waist @31.95">40 inch waist - $31.95</option> <option value="41 inch waist @31.95">41 inch waist - $31.95</option> <option value="42 inch waist @31.95">42 inch waist - $31.95</option> </select> <br><br> <input type="hidden" name="on0" value="pump model">select insulin pump model: <select name="os0"> <option value="animas 1200 series" selected>animas 1200 series</option> <option value="animas 20000 series">animas 20000 series</option> <option value="cozmo">cozmo</option> <option value="cozmo w.cozmonitor">cozmo w.cozmonitor</option> <option value="minimed 500 series">minimed 500 series</option> <option value="minimed 700 series">minimed 700 series</option> <option value="accucheck">accucheck</option> </select> <br><br> <input type="hidden" name="on1" value="style">zipper or velcro: <select name="os1"> <option value="right zip/velcro in" selected>right zip/velcro in</option> <option value="left zip/velcro in">left zip/velcro in</option> <option value="right zip/velcro out">right zip/velcro out</option> <option value="left zip/velcro out">left zip/velcro out</option> </select> <br><br> options: <select name="options" onchange="readform (this.form, false);"> <option value="please choose" selected>please choose</option> <option value="add window +3.00">add window + $3.00</option> <option value="make pouch padded +3.00">make pouch padded + $3.00</option> <option value="add velcro on belt +3.00">add velcro on belt + $3.00</option> <option value="make double pouch +10.00">make double pouch + $10.00</option> <option value="make belt loop pouch +0.00">make belt loop pouch + $0.00</option> <option value="make hook pouch +1.00">make hook pouch + $1.00</option> <option value="make vertical pouch +5.00">make vertical pouch + $5.00</option> </select> <br><br> <input type="image" src="http://www.ccaples.com/mts/scripts/cart.gif" name="submit" alt="cart add"> total cost > <input class="nbor" type="text" name="tot" size="8" value="$0.00"> <input type = "button" value = "reset form" onclick = "this.form.reset();"> </form>
Comments
Post a Comment