Advertisement
thetenfold

Untitled

Aug 8th, 2013
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement