Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 0.87 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Calculating the total of an online order form using javascript
  2. var juicePrice = new Array();
  3. juicePrice["citrusZing"]=20.00;
  4. juicePrice["strawberrySmooth"]=22.00;
  5. juicePrice["carrotSpin"]=21.50;
  6. juicePrice["Tropical"]=20.75;
  7. ...
  8.        
  9. calculateTotal()    
  10. {  
  11. var juiceForm = document.forms["juiceform"];
  12.  
  13.     //Get a reference to the juice the user Chooses name=selectedJuiceQty":
  14.     var selectedJuiceQty = juiceForm.elements["selectedJuiceQty"];
  15.  
  16.     for(var i = 0; i < selectedJuiceQty.length; i++);
  17.        
  18. for(var i = 0; i < selectedJuiceQty.length; i++){
  19.     var juiceTotal = 0;
  20.  
  21.     if(selectedJuiceQty[i]>0) {
  22.         juiceTotal += juicePrice[selectedJuiceQty[i].value]*selectedJuiceQty;
  23.         //If we get a match then we break out of this loop
  24.         break;
  25.     }
  26.     return total;
  27. }
  28.        
  29. var myPrices = new Object();
  30. myPrices['eggs'] = 1.50;
  31. myPrices['bread'] = 1.00;
  32. // ...