Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add $5.00 amount to shopping cart total when checkbox is selected

Status
Not open for further replies.

yaknowss

Programmer
Apr 19, 2012
69
US
I want the cart total to apply an additional $5.00 charge when the txtBwayEDUGift checkbox is selected. I would also like to have the ability to have that charge removed if users deselect the txtBwayEDUGift checkbox. I've included my aspx page, lines 11-233 is where you will find a javascript tag function that calculates the order total.

Thank you.

Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ConfirmBwaySeatDetails.aspx.cs"
    Inherits="SubRenewal.ConfirmBwaySeatDetails" %>
<%@ Register Assembly="TSC.Timeout" Namespace="TSC.Timeout" TagPrefix="tsc" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head id="Head1" runat="server">
    <title><%=SeasonDesc %> Subscription Renewal - Confirm your order information</title>
    <link href="css/main.css" rel="stylesheet" type="text/css" />
    <link href="css/BroadwayStyle.css" rel="stylesheet" type="text/css" />
    
    <script type="text/javascript">
    function calculate(increment, indexer)
    {
        var price = document.getElementById("divPrice" + indexer);
        var dPrice = price.innerHTML;
        dPrice = dPrice.replace("$","");
        dPrice = dPrice * 1;
        var subtotal = document.getElementById("txtSubTotal" + indexer);
        var dSubtotal = subtotal.value;
        dSubtotal = dSubtotal.replace("$","");
        dSubtotal = dSubtotal.replace(",","");
        dSubtotal = dSubtotal * 1;
        var tableRow = document.getElementById("tr" + indexer);
        if (increment == "A")
        {
            var newTotal = dSubtotal + dPrice;
            subtotal.value = "$" + newTotal.toString();
            calculateTotal(dPrice, "A");
            tableRow.style.backgroundImage = "url('images/otTableRowSelect.jpg')";
        }
        else if (increment == "S")
        {
            if (dSubtotal > 0)
            {
                var newTotal = dSubtotal - dPrice;
                if (newTotal == 0)
                {
                    subtotal.value = "";
                    calculateTotal(dPrice, "S");
                    tableRow.style.backgroundImage = "";
                    img = document.getElementById("imgSub" + indexer);
                    img.focus();
                }
                else
                {
                    subtotal.value = "$" + newTotal.toString();
                    calculateTotal(dPrice, "S");
                    img = document.getElementById("imgSub" + indexer);
                    img.focus();
                }
            }
        }
        var price2 = document.getElementById("divPrice" + indexer);
        var dPrice2 = price2.innerHTML;
        dPrice2 = dPrice2.replace("$","");
        dPrice2 = dPrice2 * 1;
        var subtotal2 = document.getElementById("txtSubTotal" + indexer);
        var dSubtotal2 = subtotal2.value;
        dSubtotal2 = dSubtotal2.replace("$","");
        dSubtotal2 = dSubtotal2 * 1;
        var txtQnty = document.getElementById("txtQnty" + indexer);
        var qnty = (dSubtotal2/dPrice2);
        if (qnty == 0)
        {
            txtQnty.value = "";
        }
        else
        {
            txtQnty.value = qnty;
        }
    }
    function calculateTotal(amountIn, type)
    {
        var total = document.getElementById("txtTotal");
        var dTotal = total.value.toString().replace("$","");
        dTotal = dTotal.replace(",","");
        dTotal = dTotal * 1;
        if (type == "A")
        {
            var newTotal = dTotal + amountIn;
            total.value = "$" + newTotal;
        }
        else if (type == "S")
        {
            var newTotal = dTotal - amountIn;
            if (newTotal == 0)
            {
                total.value = "";
            }
            else 
            {
                newTotal = addCommas(newTotal);
                total.value = "$" + newTotal;
            }
        }
    }
    function validateAmt(obj, type) //type, 0=OT League, 1=
    {
        var divPrevAmt;
        if (type == 0)
        {
            divPrevAmt = document.getElementById("divBwayGiftPrevAmt");
        }
        else if (type == 1)
        {
            divPrevAmt = document.getElementById("divBwayEDUGiftPrevPmt");
        }
        var txtAmt = document.getElementById(obj);
        var amt = txtAmt.value;
        amt = amt.toString().replace("$","");
        amt = amt.replace(",","");
        var prevAmt = divPrevAmt.innerHTML;
        try
        {
            amt = amt * 1;
        }
        catch(err)
        {
            txtAmt.value = "";
            return;
        }
        if (amt >= 0) //get the previous amount if any
        {
            if (type == 0)
            {
               if (prevAmt.toString().length > 0)
               {
                    prevAmt = prevAmt * 1;
               }
               else
               {
                    prevAmt = 0;
               }
            }
            else if (type == 1)
            {
               if (prevAmt.toString().length > 0)
               {
                    prevAmt = prevAmt * 1;
               }
               else
               {
                    prevAmt = 0;
               }
            }
        //now update the master total
        var total = document.getElementById("txtTotal");
        var dTotal = total.value.toString().replace("$","");
        dTotal = dTotal.replace(",","");
        dTotal = dTotal * 1;
        var newTotal = dTotal - prevAmt;
        newTotal = newTotal + amt;
        divPrevAmt.innerHTML = amt.toString();
        newTotal = addCommas(newTotal);
        amt = addCommas(amt);
        txtAmt.value = "$" + amt;
        total.value = "$" + newTotal;
       }
       else
       {
            txtAmt.value = "";
            return;
       }
    }
    function disable()
    {
        var txtTotal = document.getElementById("txtTotal");
        var txt = txtTotal.value;
        txtTotal.value = txt;
        var BwayGift = document.getElementById("txtBwayGift");
        BwayGift.focus();
    }
    function addCommas(nStr)
    {
	    nStr += '';
	    x = nStr.split('.');
	    x1 = x[0];
	    x2 = x.length > 1 ? '.' + x[1] : '';
	    var rgx = /(\d+)(\d{3})/;
	    while (rgx.test(x1)) {
		    x1 = x1.replace(rgx, '$1' + ',' + '$2');
	    }
	    var newTotal = x1 + x2;
	    if (newTotal.toString().indexOf(".") != -1)
	    {
	        newTotal = newTotal.substring(0,newTotal.indexOf(".") + 3);
	    }
	    return newTotal;
    }
    function checkChanged()
    {
        var cb = document.getElementById("cbOperaGala");
        if (cb.checked == true)
        {
            var tableRow = document.getElementById("trCheckbox");
            tableRow.style.backgroundImage = "url('images/otTableRowSelect.jpg')";
        }
        else if (cb.checked == false)
        {
            var tableRow = document.getElementById("trCheckbox");
            tableRow.style.backgroundImage = "";
        }
    }
    function alertIf()
    {
        var i = 0;
        for (i=5;i<=10;i++)
        {
            try{
            var subtotal2 = document.getElementById("txtSubTotal" + i);
            var dSubtotal2 = subtotal2.value;
            dSubtotal2 = dSubtotal2.replace("$","");
            dSubtotal2 = dSubtotal2 * 1;}
            catch (Error){dSubtotal2 = 0}
            if (dSubtotal2 > 0)
            {
                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.");
                break;
            }
        }
    }
    
    function disableEnterKey(e)
    {
     var key;      
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox      

    return (key != 13);
    }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div id="divContainerMain">
        <div class="header">
        </div>
        <div id="mainHolder" style="width: 800px; margin: auto; margin-top: 20px;">
             <table cellspacing="0" cellpadding="2" width="800px" style="border: solid 1px #000000">
                <tr>
                    <td colspan="5">
                        <b>Please review and confirm your order information below:</b>
                    </td>
                </tr>
                  <tr>
                    <td colspan="5">
                        &nbsp;
                    </td>
                </tr>
                  <tr>
                    <td colspan="5" style="text-align:left;">
                        <b><%=PkgDesc %> - Number of seats: <%=NumSeats %></b>
                    </td>
                </tr>
                <tr style="background-color: #590b0b; color: White; font-weight: bold; padding: 2px">
                    <td width="75">
                        Section
                    </td>
                    <td width="50" class="row">&nbsp; Row</td>
                    <td colspan="3" style="text-align:left;">
                        Seat(s)</td>
                </tr>
                <asp:Repeater ID="repSeats" runat="server">
                    <ItemTemplate>
                        <tr class="tableRow" style="border-top:dashed 1px black">
                            <td width="75" class="row">
                                <%#Eval("zoneDesc").ToString() %>
                            </td>
                            <td width="100" class="row">
                                <%#Eval("seatRow") %>
                            </td>
                            <td colspan="3" class="row" style="text-align:left;">
                                <%#Eval("seatNums") %>
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:Repeater>
                 <tr>
                    <td colspan="4" style=" background-color:#e8e8e8; border-top:dashed 1px black">
                       <div style="float:right; margin-right:40px;"><b>Subscription Price:</b> <%=AmtDue %></div>
                    </td>
                </tr>
                <tr>
                    <td style="font-weight: bold; border-top: solid 1px black; border-bottom: solid 1px black;
                        color: #590b0b" colspan="4">
                        The company is a 501(c)3 not-for-profit corporation
                        that depends on your generous contributions as well as ticket sales to keep the
                        arts alive in the Tampa Bay area.
                        <br />Would you consider making an additional tax-deductible
                        donation to support our mission?
                    </td>
                </tr>
                <tr style="background-color: #590b0b; color: White; font-weight: bold; padding: 2px">
                    <td width="100">
                    </td>
                    <td width="100">
                    </td>
                    <td width="450">
                        Gift Description
                    </td>
                    <td width="150">
                        Gift Amount
                    </td>
                </tr>
                <tr id="tr12" class="tableRow">
                    <td colspan="2" style="border-top: solid 1px black; width:200px;">
                    &nbsp;
                    </td>
                    <td width="450" style="border-top: solid 1px black;">
                        <strong>Add a gift to support</strong><br />
                        <a href="MemberBenefits.html" target="_blank">Member Benefits</a>
                    </td>
                    <td width="150" style="border-top: solid 1px black;">
                        <input id="txtBwayGift" type="text" style="width: 75px" onkeypress="return disableEnterKey(event);"
                        onchange="validateAmt(this.id, 0);" runat="server" />
                        <div id="divBwayGiftPrevAmt" style="color: #fff; font-size: 1px">
                        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                    </td>
                </tr>
                <tr id="tr13" class="tableRow">
                    <td colspan="2" style="border-top: solid 1px black; width:200px;">
                    &nbsp;
                    </td>
                    <td width="450" style="border-top: solid 1px black;">
                        <strong>Add $5 to Support arts education</strong><br />
                    </td>
                    <td width="150" style="border-top: solid 1px black;">
                      <input id="txtBwayEDUGift" type="checkbox" checked="checked" runat="server" /> <strong>Yes</strong>
                        <div id="divBwayEDUGiftPrevPmt" style="color: #fff; font-size: 1px">
                        </div>
                    </td>
                </tr>
                <tr id="tr1" class="row3">
                    <td colspan="2" style="border-top: solid 1px black; width:200px;">
                    &nbsp;
                    </td>
                    <td width="450" style="border-top: solid 1px black;">
                        <strong>Cart total will reflect gift amount upon checkout.</strong><br />
                    </td>
                    <td width="150" style="border-top: solid 1px black;">&nbsp;
                     </td>
                </tr>
                <tr>
                     <td colspan="4" class="row3" style="padding-left:60px";>&nbsp;
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <div style="width: 800px">
                            <div style="float: right; margin: 0 48px 0 10px; width:75px">
                                <asp:TextBox ID="txtTotal" runat="server" Width="75px" BorderColor="Black" BorderWidth="1px"
                                    onblur="disable();" onfocus="disable();" onchange="disable();"></asp:TextBox>
                            </div>
                            <div style="float: right;">
                                <b>Total:</b></div>
                        </div>
                    </td>
                </tr>
                <tr>
                      <td colspan="4" class="row">
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <div style="width: 800px">
                            <div style="float: right; margin: 0 45px 0 10px; width: 100px">
                                <div class="btnSmallActive" style="float: left; margin: 5px 0 0 20px">
                                    <a>
                                        <asp:ImageButton ID="btnCheckout" runat="server" ImageUrl="images/checkOut.png" 
                                        OnClick="btnCheckout_Click" /></a></div>
                            </div>
                        </div>
                    </td>
                </tr>
             </table>
            <br />
            <br />
        </div>
        <div id="footer" class="footer">
        </div>
    </div>
    <script type="text/javascript">
    var amtDue = '<%=AmtDue %>';
    var total = document.getElementById("txtTotal");
    total.value = amtDue;
    </script>
     </form>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top