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

Untitled

By: a guest on Aug 21st, 2012  |  syntax: None  |  size: 2.61 KB  |  hits: 14  |  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. /*
  2. This source is shared under the terms of LGPL 3
  3. www.gnu.org/licenses/lgpl.html
  4.  
  5. You are free to use the code in Commercial or non-commercial projects
  6. */
  7.  
  8.  //Set up an associative array
  9.  //The keys represent the binding
  10.  var binding_prices = new Array();
  11.  binding_prices["hardcover"]=5;
  12.  binding_prices["softcover"]=4;
  13.  binding_prices["brochure"]=3;
  14.  binding_prices["sbinding"]=2;
  15.  
  16.  //Set up an associative array
  17.  //The keys represent the pages
  18.  var pages_prices= new Array();
  19.  pages_prices["25pages"]=0;
  20.  pages_prices["50pages"]=5;
  21.  pages_prices["75pages"]=5;
  22.  pages_prices["100pages"]=7;
  23.  pages_prices["125pages"]=8;
  24.  pages_prices["150pages"]=10;
  25.  pages_prices["175pages"]=5;
  26.  pages_prices["200pages"]=9;
  27.  pages_prices["225pages"]=5;
  28.  pages_prices["250pages"]=5;
  29.  pages_prices["275pages"]=8;
  30.  pages_prices["300pages"]=7;
  31.  
  32.  //Set up an associative array
  33.  //The keys represent the pages
  34.  var quantity_prices= new Array();
  35.  quantity_prices["30pcs"]=8;
  36.  quantity_prices["50pcs"]=7;
  37.  quantity_prices["100pcs"]=5;
  38.  quantity_prices["200pcs"]=3;
  39.  quantity_prices["300pcs"]=0;
  40.  
  41. function getBindingPrice()
  42. {
  43.     var bindingPrice=0;
  44.     //Get a reference to the form id="choice_books"
  45.     var theForm = document.forms["choice_books"];
  46.     //Get a reference to the select id="binding"
  47.      var selectedBinding = theForm.elements["binding"];
  48.  
  49.     bindingPrice = binding_prices[selectedBinding.value];
  50.  
  51.     return bindingPrice;
  52. }
  53.  
  54. function getPagesPrice()
  55. {
  56.     var pagesPrice=0;
  57.     //Get a reference to the form id="choice_books"
  58.     var theForm = document.forms["choice_books"];
  59.     //Get a reference to the select id="binding"
  60.      var selectedPages = theForm.elements["pages"];
  61.  
  62.     pagesPrice = pages_prices[selectedPages.value];
  63.  
  64.     return pagesPrice;
  65. }
  66.  
  67. function getQuantityPrice()
  68. {
  69.     var quantityPrice=0;
  70.     //Get a reference to the form id="choice_books"
  71.     var theForm = document.forms["choice_books"];
  72.     //Get a reference to the select id="binding"
  73.      var selectedQuantity = theForm.elements["quantity"];
  74.  
  75.     quantityPrice = quantity_prices[selectedQuantity.value];
  76.  
  77.     return quantityPrice;
  78. }    
  79.        
  80. function calculateTotal()
  81. {
  82.     //Here we get the total price by calling our function
  83.     //Each function returns a number so by calling them we add the values they return together
  84.     var bookPrice = getBindingPrice() + getPagesPrice() + getQuantityPrice();
  85.    
  86.     //display the result
  87.     var divobj = document.getElementById('totalPrice');
  88.     divobj.style.display='block';
  89.     divobj.innerHTML = "Gesamtpreis €"+cakePrice;
  90.  
  91. }
  92.  
  93. function hideTotal()
  94. {
  95.     var divobj = document.getElementById('totalPrice');
  96.     divobj.style.display='none';
  97. }