Solved

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

Posted on 2012-12-27
16
292 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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
 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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