Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. // Skrypt 4.3 - shopping.js - wersja 2.
  2. // This script calculates an order total.
  3.  
  4. // Funkcja wywoływana w momencie wysyłania formularza.
  5. // Funkcja przeprowadza obliczenia i zwraca wartość false.
  6. function calculate() {
  7. 'use strict';
  8.  
  9. var total;
  10. var cost1;
  11. var cost2;
  12.  
  13.  
  14. var dishw = document.getElementById('dishw').value;
  15. var pills = document.getElementById('pills').value;
  16. var rin = document.getElementById('rin').value;
  17. var water = document.getElementById('water').value;
  18. var electri = document.getElementById('electri').value;
  19. var days = document.getElementById('days').value;
  20.  
  21. var water2 = document.getElementById('water2').value;
  22. var liquid = document.getElementById('liquid').value;
  23. var rubber = document.getElementById('rubber').value;
  24. var scour = document.getElementById('scour').value;
  25.  
  26. var pom = (pills + water + electri);
  27. //pom *= days;
  28.  
  29. cost1 = (pom + rin);//*12;
  30. cost2 = (water2 * days) + liquid + rubber + scour;
  31. //cost2 *=12;
  32. //cost1 = cost1.toFixed(2);
  33. //cost2 = cost2.toFixed(2);
  34.  
  35.  
  36.  
  37. total = dishw / cost1;
  38.  
  39.  
  40. // Zmień format sumy:
  41. total = total.toFixed(1);
  42.  
  43. document.getElementById('cost1').value = cost1;
  44. document.getElementById('cost2').value = cost2;
  45.  
  46. document.getElementById('total').value = total;
  47. return false;
  48. } // Koniec funkcji calculate().
  49.  
  50. function init() {
  51. 'use strict';
  52. document.getElementById('theForm').onsubmit = calculate;
  53. } // Koniec funkcji init().
  54. window.onload = init;
  55.  
  56.  
  57.  
  58.  
  59. /* dzialajacy calculate
  60. function calculate() {
  61. 'use strict';
  62. var total;
  63. var quantity = document.getElementById('quantity').value;
  64. var price = document.getElementById('price').value;
  65. var tax = document.getElementById('tax').value;
  66. var discount = document.getElementById('discount').value;
  67. total = quantity * price;
  68. tax /= 100;
  69. tax++;
  70. total *= tax;
  71. total -= discount;
  72.  
  73. // Zmień format sumy:
  74. total = total.toFixed(2);
  75.  
  76. document.getElementById('total').value = total;
  77. return false;
  78. } // Koniec funkcji calculate().
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement