473,387 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Switching to toggle buttons in the code provided

This AS2 code is a small shopping cart. What I'm trying to do here is change that when the add to cart button is clicked the items are added to the text fields in the shopping cart movie clip. But when it's clicked again, I want the items to be removed from the cart. i've tried changing the code on line 24 to
Expand|Select|Wrap|Line Numbers
  1. quantities[poz] -= itQ;
and it works, but if you press the add to cart button again, it just keeps reducing the price. Any help will be appreciated!!!


Expand|Select|Wrap|Line Numbers
  1. currency_code = "USD";
  2. init = function(){
  3.     shoppingcart.items = "";
  4.     shoppingcart.amounts = "";
  5.     shoppingcart.quantities = "";
  6.     shoppingcart.total = "0 "+currency_code;
  7.     items = new Array();
  8.     amounts = new Array();
  9.     quantities = new Array();
  10. }
  11. addItem = function(itN,itA,itQ){
  12.     if(items.length > 0){
  13.         poz = -1;
  14.         for(i=0;i<items.length;i++){
  15.             if(items[i] == itN){
  16.                 poz = i;
  17.             }
  18.         }
  19.         if(poz == -1){
  20.             items.push(itN);
  21.             amounts.push(itA);
  22.             quantities.push(itQ);
  23.         }else{
  24.             quantities[poz] += itQ;
  25.         }
  26.     }else{
  27.         items.push(itN);
  28.         amounts.push(itA);
  29.         quantities.push(itQ);
  30.     }
  31.     shoppingcart.items = "";
  32.     shoppingcart.amounts = "";
  33.     shoppingcart.quantities = "";
  34.     shoppingcart.total = 0;
  35.     for(i=0;i<items.length;i++){
  36.         shoppingcart.items += items[i]+"<br>";
  37.         shoppingcart.amounts += amounts[i]+" "+currency_code+"<br>";
  38.         shoppingcart.quantities += quantities[i]+"<br>";
  39.         shoppingcart.total += amounts[i] * quantities[i];
  40.     }
  41.     shoppingcart.total += " "+currency_code;
  42. }
  43. sendToPayPal = function(){
  44.     if(items.length > 0){
  45.         paypal = new LoadVars();
  46.         paypal.cmd = "_cart";
  47.         paypal.upload = "1";
  48.         paypal.no_note = "1";
  49.         paypal.business = "necromanthus@yahoo.com";
  50.         paypal.currency_code = currency_code;
  51.         for (n=0; n<items.length; n++) {
  52.             paypal["item_name_"+(n+1)] = items[n];
  53.             paypal["amount_"+(n+1)] = amounts[n];
  54.             paypal["quantity_"+(n+1)] = quantities[n];
  55.         }
  56.         paypal.send("https://www.paypal.com/cgi-bin/webscr", "_blank", "POST");
  57.     }
  58. }
  59.  
  60. but1.onRelease=function(){
  61.     addItem("Intel Core 2 Duo E6850",270,1);
  62. }
  63. but2.onRelease=function(){
  64.     addItem("Intel Core 2 Quad Q6700",550,1);
  65. }
  66. but3.onRelease=function(){
  67.     addItem("Intel Core 2 Extreme QX6850",1000,1);
  68. }
  69. but4.onRelease=function(){
  70.     addItem("Wordpress Blog",750,1);
  71. }
  72. checkout.onRelease=function(){
  73.         sendToPayPal();
  74. }
  75. init();
  76. stop();
Nov 20 '10 #1
0 1360

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: foldface | last post by:
Hi This works but is a bit long-winded. Is there a better way? ta F <style> ..Header { background-color: gray;
11
by: MLH | last post by:
Why is that? If I choose the tiny check boxes which are hard to hit with a mouse, it works fine. But option buttions, shich can be sized big enough for people with limited sight and dexterity...
1
by: John | last post by:
Hi How can I make some of the buttons on BindingNavigator toggle i.e. when one button is clicked others unclick automatically? Thanks Regards
4
by: cwoll | last post by:
I am runing this function to toggle buttens to display an "X" when they is selected, the butten is linked to a yes/no field. This function works good, the problem I am having is that when I make a...
2
by: Telvanni | last post by:
Ok I'm having problems just figuring out how to convert this Sorter void BubbleSort (int list, int length) { int temp; int counter; int index; for (counter = 0;...
2
stonward
by: stonward | last post by:
Hiya People, I've put two toggle buttons in a frame...so only one can be 'active' at any one time. When one is 'live' (option 1, say) I want the Form to show my Trade price values, when the other,...
2
by: Chuck | last post by:
How can I make an array of command buttons (or toggle buttons) on a form and have a text box on the same form display the index of the button clicked? This works very well in VB6, but I can't...
2
by: 6afraidbecause789 | last post by:
Hi - Has anyone ever used toggle buttons to select items in a listbox? I'd like to put about 24 toggle buttons on an unbound form that select or deselect items in a multiple select listbox. I've...
2
by: codefragment | last post by:
Hi I'm trying to get the InfoMessage code below working. What I'm finding is that the print statements have to be before the select statement, which kind of defies the point in my scenario. e.g....
4
by: kanchmandre | last post by:
I have created one user control having text-box and icon.On click of an icon a calendar gets created on client side.The date will get selected and set to text-box on selection of any date. I have...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.