Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!

Untitled

By: thetenfold on Aug 8th, 2013  |  syntax: JavaScript  |  size: 0.90 KB  |  views: 293  |  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. <script type="text/javascript">
  2.  
  3. var productpr, qty;
  4.  
  5. function price() {
  6.     var productpr = document.getElementsByName('productpr')[0],
  7.         info = productpr.options[productpr.selectedIndex].value;
  8.     return parseInt( info.split(':')[1], 10 );
  9. }
  10.  
  11. function quantity() {
  12.     return parseInt(qty.value, 10);
  13. }
  14.  
  15. function update_subtotal(event) {
  16.     var subtotal = document.getElementById('subtotal').getElementsByTagName('b')[0];
  17.     subtotal.textContent = '$' + ( price() * quantity() ).toFixed(2);
  18. }
  19.  
  20. window.addEventListener('load', function (event) {
  21.     productpr = document.getElementsByName('productpr')[0];
  22.     qty = document.getElementsByName('qty')[0];
  23.     productpr.addEventListener('change', update_subtotal, false);
  24.     qty.addEventListener('keyup', update_subtotal, false);
  25.     update_subtotal(); // just in-case if they refreshed the page and kept the values
  26. }, false);
  27.  
  28. </script>