Solved

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

Posted on 2012-12-27
16
287 Views
Last Modified: 2013-01-13
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 attached my aspx page, lines 11-233 is where you will find a javascript tag function that calculates the order total.

Thank you.
ConfirmBwaySeatDetails.aspx
0
Comment
Question by:is_staff
  • 10
  • 3
  • 3
16 Comments
 
LVL 19

Expert Comment

by:Manoj Patil
ID: 38725134
Try this javascript

function AddAmount(checkbox)
{
    if (checkbox.checked)
    {
        var txtCartTotal= document.getElementById("txtCartValue");
        int temp=txtCartTotal.value + 5;
    }
    else
    {
       var txtCartTotal= document.getElementById("txtCartValue");
        int temp=txtCartTotal.value - 5;
    }
}

Open in new window



HTML CODE -
<input type="checkbox" name="txtBwayEDUGift" onclick="AddAmount(this)" />

Open in new window

0
 

Author Comment

by:is_staff
ID: 38725151
Okay, I'll give it a shot and let you know the results. You may not hear back from me until tomorrow morning. Thank you!
0
 

Author Comment

by:is_staff
ID: 38727472
Hi there,

So after applying your code I went to debug and encountered the following instances:

Sample1 - Cart is not adding $5.oo to total.
Sample2 - Is the message i received when I unchecked the check box.
sample1.jpg
sample2.jpg
0
 
LVL 19

Expert Comment

by:Manoj Patil
ID: 38727769
0
 

Author Comment

by:is_staff
ID: 38728026
Hmm.. this didnt help me. If you have any other thoughts I would greatly appreciate it. Thank you
0
 
LVL 19

Expert Comment

by:Manoj Patil
ID: 38728177
Get the Code from same site
See example here.
http://jsbin.com/abukor/2
It displaying the alert message. You can edit it by my previous code.
For addition you first need to parse the text box value like

int temp1=parseInt(txtCartTotal.value,0) + 5;
0
 

Author Comment

by:is_staff
ID: 38728201
Thank you for your response. I'm having difficulty interpreting the examples you provided.  Maybe I am overlooking something? To my understanding, the examples provide a pop up message and that is not what i am looking for. I was hoping to enable javascript to add a $5.00 amount to the cart total.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 38731051
I would use your calculator function to handle this:

function AddAmount(checkbox)
{
    var action = "";
    var dGift = 5;
    if (checkbox.checked)
    {
        action = "A";
    }
    else
    {
        action = "S";
    }
    calculateTotal(gift, action)
}

Open in new window


/gustav
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:is_staff
ID: 38732583
Okay, I'll give it a shot and let you know my result. Thank you.
0
 

Author Comment

by:is_staff
ID: 38736751
cactus_data -

Thank you for your input. I tested your code. The cart total is now including the additional $5.00 charge. When the checkbox is unchecked, it is reducing the amount in the cart total, however, it is not reducing the subscription price. See my attached screen shots for further clarification.

Thank you.
1.jpg
2.jpg
0
 

Author Comment

by:is_staff
ID: 38742052
I added the following code:

<input type="checkbox" name="txtBwayEDUGift" onchange="checkboxAdd(this);" checked="checked" />
<script type="text/javascript">
function checkboxAdd( ctl ){
 if(ctl.checked == true ){
   calculateTotal(5, "A");
  } else {
   calculateTotal( 5, "S");
  }
} 

It appears the functionality is there and is working to an extent. But instead of adding the $5.00 charge to the order, it is instead keeping the orginal amount and only reducing the amount when unchecked. It is not adding the $5.00 to the order amount when checked. Please see my screenshots attached. With the $5.00 added the order amount should be $1,126.00 in my example. I hope this makes sense. Please help in anyway possible. thank you.


</script>  

Open in new window

1.jpg
2.jpg
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 38743588
I don't know, but you could use a similar technique to adjust the other (total)field.

/gustav
0
 

Author Comment

by:is_staff
ID: 38743800
how so?
0
 

Accepted Solution

by:
is_staff earned 0 total points
ID: 38755123
got it. I needed to add jquery to make it work:

function load()
{
alert("Page is loaded");
}
</script>
</head>

Open in new window


<body onload="load()">

Open in new window



I also needed to add this to my c# page:

if (txtBwayEDUGift.Checked)
            {
                addDonations(5.00m, 93);
            }

Open in new window

0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 38755200
Great!

/gustav
0
 

Author Closing Comment

by:is_staff
ID: 38771593
discovered answer by adding jquery and c# code to existing solution.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now