Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2012-12-27
16
Medium Priority
?
300 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 51

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 51

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 51

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 Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

704 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