View Single Post
  #2 (permalink)  
Old 02-10-09, 04:35 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
Hi,

Tjhis should work. You were not passing any values for the selected pizza size. I added some functionality. It does require that you use a $ sign in the text of the select list. Further comments in the code. I highlighted the changes in red:

Code:
<html>
<head>
    <title>Pizza Order Form</title>
    <meta content="text/html; charset=windows-1252" http-equiv="Content-Type" />

    <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" || obj.type == "radio") { // checkboxes 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
                            }
                            // Now we do 3-character tokens...
                            if (ary[j].length < 4) continue;
                            tok = ary[j].substring(0, 3); // first 3 chars
                            val = ary[j].substring(3); // get data
                            if (tok == "s1=") { // value for shipping
                                if (obj1.shipping) obj1.shipping.value = val;
                                ary[j] = ""; // clear it out
                            }
                            if (tok == "s2=") { // value for shipping2
                                if (obj1.shipping2) obj1.shipping2.value = val;
                                ary[j] = ""; // clear it out
                            }
                        }
                        val = ary.join(" "); // rebuild val with what's left

                        tag = obj.name.substring(obj.name.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;
                    }
                }
	else if (obj.name == 'basedes' && obj.selectedIndex != 0){ //calculate when pizza selected, but dont calculate if nothing selected yet
	    var select_list_selected_index = obj.selectedIndex;
	    // get text of select list. not value because your show/hide code depends on it and we cant change it
	    var text = obj.options[select_list_selected_index].text;
					
                    ary = text.split("$");  //split at $ sign
                    val = ary[1]; // get the second item = the amount
                    amt = amt + eval(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>

    <script src="FormManager.js">
        /****************************************************
        * Form Dependency Manager- By Twey- http://www.twey.co.uk
        * Visit Dynamic Drive for this script and more: http://www.dynamicdrive.com
        ****************************************************/
    </script>

    <script type="text/javascript">
        window.onload = function() {
            setupDependencies('weboptions'); //name of form(s). Seperate each with a comma (ie: 'weboptions', 'myotherform' )
        };
    </script>

</head>
<body>
    <form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="this.target='_blank'; return ReadForm(this, true);"
    name="weboptions">
    <input type="hidden" name="cmd" value="_cart" />
    <input type="hidden" name="add" value="1" />
    <input type="hidden" name="business" value="sdc.pr1@gmail.com " />
    <input type="hidden" name="shipping" value="0.00" />
    <input type="hidden" name="no_shipping" value="1" />
    <input type="hidden" name="return" value="http://sdc.110mb.com/waldypizza/menu.htm" />
    <input type="hidden" name="item_name" />
    <input type="hidden" name="amount" />
    <input type="hidden" name="currency_code" value="USD" />
    <input type="hidden" name="lc" value="US" />
    <input type="hidden" name="bn" value="PP-ShopCartBF" />
    &nbsp;<strong><font face="Arial" size="5">Select the pizza size:</font></strong>
    <p>
        <select size="1" onclick="ReadForm (this.form, false);" name="basedes">
            <option selected="selected">Pizza Sizes:</option>
            <option value="Small Pizza">Small Pizza - $5.00</option>
            <option value="Medium Pizza">Medium Pizza - $7.00</option>
            <option value="Large Pizza">Large Pizza - $10.00</option>
        </select></p>
    <p>
        &nbsp;</p>
    <p>
        <strong><font face="Arial" size="4">Add any of the following toppings you want.
            <br />
            The larger size of Pizza you select, the higher the price for the toppings:</font></strong></p>
    <p>
        <label>
            <input class="DEPENDS ON basedes BEING Small Pizza" type="checkbox" onclick="ReadForm (this.form, false);"
                name="pepperoni" value="pepperoni +1.50" />Pepperoni, add: $1.50</label>
        <label>
            <input class="DEPENDS ON basedes BEING Medium Pizza" type="checkbox" onclick="ReadForm (this.form, false);"
                name="pepperoni" value="pepperoni +2.75" />Pepperoni, add: $2.76</label>
        <label>
            <input class="DEPENDS ON basedes BEING Large Pizza" type="checkbox" onclick="ReadForm (this.form, false);"
                name="pepperoni" value="pepperoni +4.00" />Pepperoni, add: $4.00</label><br />
        <label>
            <input class="DEPENDS ON basedes BEING Small Pizza" type="checkbox" onclick="ReadForm (this.form, false);"
                name="onions" value="onions +1.25" />Onions, add: $1.25</label>
        <label>
            <input class="DEPENDS ON basedes BEING Medium Pizza" type="checkbox" onclick="ReadForm (this.form, false);"
                name="onions" value="onions +2.50" />Onions, add: $2.50</label>
        <label>
            <input class="DEPENDS ON basedes BEING Large Pizza" type="checkbox" onclick="ReadForm (this.form, false);"
                name="onions" value="onions +3.75" />Onions, add: $3.75</label><br />
        <label>
            <input class="DEPENDS ON basedes BEING Small Pizza" type="checkbox" onclick="ReadForm (this.form, false);"
                name="peppers" value="peppers +1.25" />Peppers, add: $1.25</label>
        <label>
            <input class="DEPENDS ON basedes BEING Medium Pizza" type="checkbox" onclick="ReadForm (this.form, false);"
                name="peppers" value="peppers +2.50" />Peppers, add: $2.50</label>
        <label>
            <input class="DEPENDS ON basedes BEING Large Pizza" type="checkbox" onclick="ReadForm (this.form, false);"
                name="peppers" value="peppers +3.75" />Peppers, add: $3.75</label><br />
        <label>
            <input class="DEPENDS ON basedes BEING Small Pizza" type="checkbox" onclick="ReadForm (this.form, false);"
                name="mushrooms" value="mushrooms +1.45" />Mushrooms, add: $1.45</label>
        <label>
            <input class="DEPENDS ON basedes BEING Medium Pizza" type="checkbox" onclick="ReadForm (this.form, false);"
                name="mushrooms" value="mushrooms +2.65" />Mushrooms, add: $2.65</label>
        <label>
            <input class="DEPENDS ON basedes BEING Large Pizza" type="checkbox" onclick="ReadForm (this.form, false);"
                name="mushrooms" value="mushrooms +3.85" />Mushrooms, add: $3.85</label><br />
        <label>
            <input class="DEPENDS ON basedes BEING Small Pizza" type="checkbox" onclick="ReadForm (this.form, false);"
                name="shrimp" value="shrimp +3.55" />Shrimp, add: $3.55</label>
        <label>
            <input class="DEPENDS ON basedes BEING Medium Pizza" type="checkbox" onclick="ReadForm (this.form, false);"
                name="shrimp" value="shrimp +4.75" />Shrimp, add: $4.75</label>
        <label>
            <input class="DEPENDS ON basedes BEING Large Pizza" type="checkbox" onclick="ReadForm (this.form, false);"
                name="shrimp" value="shrimp +5.95" />Shrimp, add: $5.95</label></p>
    <p>
        Total:
        <input class="nbor" size="7" name="tot" type="text" /></p>
    <p>
        <input type="submit" name="B1" value="Submit" /></p>
    </form>
</body>
</html>
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish

Last edited by Yeroon; 02-10-09 at 04:37 AM.
Reply With Quote