Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-04-2013, 03:49 PM   PM User | #1
yaknowss
New to the CF scene

 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
yaknowss is an unknown quantity at this point
Add $5.00 to cart total when input type check box value is checked

I am trying to modify the function checkboxAdd(txtBwayEDUGift) to add a $5.00 amount to the total cart order when the checkbox txtBwayEDUGift is checked. It is currently reducing the cart total $5.00 when unchecked, however, it is not adding $5.00 to the cart total when txtBwayEDUGift is checked. I can supply more information if needed. Thank you in advance for your help.

Code:
01.<script type="text/javascript">   
02.    function calculate(increment, indexer)   
03.    {   
04.        var price = document.getElementById("divPrice" + indexer);   
05.        var dPrice = price.innerHTML;   
06.        dPrice = dPrice.replace("$","");   
07.        dPrice = dPrice * 1;   
08.        var subtotal = document.getElementById("txtSubTotal" + indexer);   
09.        var dSubtotal = subtotal.value;   
10.        dSubtotal = dSubtotal.replace("$","");   
11.        dSubtotal = dSubtotal.replace(",","");   
12.        dSubtotal = dSubtotal * 1;   
13.        var tableRow = document.getElementById("tr" + indexer);   
14.        if (increment == "A")   
15.        {   
16.            var newTotal = dSubtotal + dPrice;   
17.            subtotal.value = "$" + newTotal.toString();   
18.            calculateTotal(dPrice, "A");   
19.            tableRow.style.backgroundImage = "url('images/otTableRowSelect.jpg')";   
20.        }   
21.        else if (increment == "S")   
22.        {   
23.            if (dSubtotal > 0)   
24.            {   
25.                var newTotal = dSubtotal - dPrice;   
26.                if (newTotal == 0)   
27.                {   
28.                    subtotal.value = "";   
29.                    calculateTotal(dPrice, "S");   
30.                    tableRow.style.backgroundImage = "";   
31.                    img = document.getElementById("imgSub" + indexer);   
32.                    img.focus();   
33.                }   
34.                else  
35.                {   
36.                    subtotal.value = "$" + newTotal.toString();   
37.                    calculateTotal(dPrice, "S");   
38.                    img = document.getElementById("imgSub" + indexer);   
39.                    img.focus();   
40.                }   
41.            }   
42.        }   
43.        var price2 = document.getElementById("divPrice" + indexer);   
44.        var dPrice2 = price2.innerHTML;   
45.        dPrice2 = dPrice2.replace("$","");   
46.        dPrice2 = dPrice2 * 1;   
47.        var subtotal2 = document.getElementById("txtSubTotal" + indexer);   
48.        var dSubtotal2 = subtotal2.value;   
49.        dSubtotal2 = dSubtotal2.replace("$","");   
50.        dSubtotal2 = dSubtotal2 * 1;   
51.        var txtQnty = document.getElementById("txtQnty" + indexer);   
52.        var qnty = (dSubtotal2/dPrice2);   
53.        if (qnty == 0)   
54.        {   
55.            txtQnty.value = "";   
56.        }   
57.        else  
58.        {   
59.            txtQnty.value = qnty;   
60.        }   
61.    }   
62.    function calculateTotal(amountIn, type)   
63.    {   
64.        var total = document.getElementById("txtTotal");   
65.        var dTotal = total.value.toString().replace("$","");   
66.        dTotal = dTotal.replace(",","");   
67.        dTotal = dTotal * 1;   
68.        if (type == "A")   
69.        {   
70.            var newTotal = dTotal + amountIn;   
71.            total.value = "$" + newTotal;   
72.        }   
73.        else if (type == "S")   
74.        {   
75.            var newTotal = dTotal - amountIn;   
76.            if (newTotal == 0)   
77.            {   
78.                total.value = "";   
79.            }   
80.            else    
81.            {   
82.                newTotal = addCommas(newTotal);   
83.                total.value = "$" + newTotal;   
84.            }   
85.        }   
86.    }   
87.    function validateAmt(obj, type) //type, 0=OT League, 1=Straz   
88.    {   
89.        var divPrevAmt;   
90.        if (type == 0)   
91.        {   
92.            divPrevAmt = document.getElementById("divBwayGiftPrevAmt");   
93.        }   
94.        else if (type == 1)   
95.        {   
96.            divPrevAmt = document.getElementById("divBwayEDUGiftPrevPmt");   
97.        }   
98.        var txtAmt = document.getElementById(obj);   
99.        var amt = txtAmt.value;   
100.        amt = amt.toString().replace("$","");   
101.        amt = amt.replace(",","");   
102.        var prevAmt = divPrevAmt.innerHTML;   
103.        try  
104.        {   
105.            amt = amt * 1;   
106.        }   
107.        catch(err)   
108.        {   
109.            txtAmt.value = "";   
110.            return;   
111.        }   
112.        if (amt >= 0) //get the previous amount if any   
113.        {   
114.            if (type == 0)   
115.            {   
116.               if (prevAmt.toString().length > 0)   
117.               {   
118.                    prevAmt = prevAmt * 1;   
119.               }   
120.               else  
121.               {   
122.                    prevAmt = 0;   
123.               }   
124.            }   
125.            else if (type == 1)   
126.            {   
127.               if (prevAmt.toString().length > 0)   
128.               {   
129.                    prevAmt = prevAmt * 1;   
130.               }   
131.               else  
132.               {   
133.                    prevAmt = 0;   
134.               }   
135.            }   
136.        //now update the master total   
137.        var total = document.getElementById("txtTotal");   
138.        var dTotal = total.value.toString().replace("$","");   
139.        dTotal = dTotal.replace(",","");   
140.        dTotal = dTotal * 1;   
141.        var newTotal = dTotal - prevAmt;   
142.        newTotal = newTotal + amt;   
143.        divPrevAmt.innerHTML = amt.toString();   
144.        newTotal = addCommas(newTotal);   
145.        amt = addCommas(amt);   
146.        txtAmt.value = "$" + amt;   
147.        total.value = "$" + newTotal;   
148.       }   
149.       else  
150.       {   
151.            txtAmt.value = "";   
152.            return;   
153.       }   
154.    }   
155.    function disable()   
156.    {   
157.        var txtTotal = document.getElementById("txtTotal");   
158.        var txt = txtTotal.value;   
159.        txtTotal.value = txt;   
160.        var BwayGift = document.getElementById("txtBwayGift");   
161.        BwayGift.focus();   
162.    }   
163.    function addCommas(nStr)   
164.    {   
165.        nStr += '';   
166.        x = nStr.split('.');   
167.        x1 = x[0];   
168.        x2 = x.length > 1 ? '.' + x[1] : '';   
169.        var rgx = /(\d+)(\d{3})/;   
170.        while (rgx.test(x1)) {   
171.            x1 = x1.replace(rgx, '$1' + ',' + '$2');   
172.        }   
173.        var newTotal = x1 + x2;   
174.        if (newTotal.toString().indexOf(".") != -1)   
175.        {   
176.            newTotal = newTotal.substring(0,newTotal.indexOf(".") + 3);   
177.        }   
178.        return newTotal;   
179.    }   
180.    function checkChanged()   
181.    {   
182.        var cb = document.getElementById("cbOperaGala");   
183.        if (cb.checked == true)   
184.        {   
185.            var tableRow = document.getElementById("trCheckbox");   
186.            tableRow.style.backgroundImage = "url('images/otTableRowSelect.jpg')";   
187.        }   
188.        else if (cb.checked == false)   
189.        {   
190.            var tableRow = document.getElementById("trCheckbox");   
191.            tableRow.style.backgroundImage = "";   
192.        }   
193.    }   
194.    function alertIf()   
195.    {   
196.        var i = 0;   
197.        for (i=5;i<=10;i++)   
198.        {   
199.            try{   
200.            var subtotal2 = document.getElementById("txtSubTotal" + i);   
201.            var dSubtotal2 = subtotal2.value;   
202.            dSubtotal2 = dSubtotal2.replace("$","");   
203.            dSubtotal2 = dSubtotal2 * 1;}   
204.            catch (Error){dSubtotal2 = 0}   
205.            if (dSubtotal2 > 0)   
206.            {   
207.                alert("You have selected the I want it all package, \n however you have also selected individual tickets to the same events. \n If you meant to do this, please disregard this message.");   
208.                break;   
209.            }   
210.        }   
211.    }   
212.       
213.    function disableEnterKey(e)   
214.    {   
215.     var key;         
216.     if(window.event)   
217.          key = window.event.keyCode; //IE   
218.     else  
219.          key = e.which; //firefox         
220.  
221.    return (key != 13);   
222.    }   
223.    //Add $5.00 donation to cart   
224.    function checkboxAdd(txtBwayEDUGift)    
225.    {   
226.        if (txtBwayEDUGift.checked == true) {   
227.            // alert("adding $5");   
228.            calculateTotal(5, "A");   
229.        } else {   
230.            //alert("deducting $5");   
231.            calculateTotal(5, "S");   
232.        }   
233.    }   
234.    //note this only works in newer browsers. if older browsers are of concern then you should adapt accordingly   
235.    document.addEventListener('DOMContentLoaded',   
236.                           checkboxAdd(document.getElementById('txtBwayEDUGift')));   
237.  
238.  
239.    </script>
yaknowss is offline   Reply With Quote
Old 01-04-2013, 04:07 PM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
Those line numbers aren't helping anybody. Do you have a version without?
xelawho is offline   Reply With Quote
Reply

Bookmarks

Tags
asp, asp.net, java, javascript

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:10 AM.


Advertisement
Log in to turn off these ads.