-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproductSizeCalc.js
72 lines (47 loc) · 1.94 KB
/
productSizeCalc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Calculator
var width = document.querySelector('input[name=width]');
var length = document.querySelector('input[name=length]');
var totalArea = document.querySelector('.totalArea');
var widthMax = document.querySelector('#calcWidth');
var lengthMax = document.querySelector('#calcLength');
var costMultiplier = document.querySelector('#calcCostMultiplier');
var finalCost = document.querySelector('.finalCost');
var finalCalculatedCost = document.querySelector('#finalCalcCost');
var calc = function () {
width.addEventListener('keyup', function(){
var roundedInt = Number.parseFloat((this.value * length.value)/1000).toFixed(4);
if (Number(width.value) > Number(widthMax.value)) {
width.value = widthMax.value;
} else if (Number(width.value) < 0){
width.value = 0;
}
if (roundedInt < 0) {
roundedInt = 0;
}
var areaMtrSqrWidth = (roundedInt / 1000);
totalArea.textContent = Number.parseFloat(areaMtrSqrWidth).toFixed(4);
areaMtrSqrWidth *= costMultiplier.value;
areaMtrSqrWidth = Number.parseFloat(areaMtrSqrWidth).toFixed(2);
finalCost.textContent = areaMtrSqrWidth;
finalCalculatedCost.value = (finalCost.textContent/1.2);
});
length.addEventListener('keyup', function(){
var roundedInt = Number.parseFloat((this.value * width.value)/1000).toFixed(4);
if(Number(length.value) > Number(lengthMax.value)) {
length.value = lengthMax.value;
}else if (Number(length.value) < 0){
length.value = 0;
}
if (roundedInt < 0) {
roundedInt = 0;
}
var areaMtrSqrWidth = (roundedInt / 1000);
totalArea.textContent = Number.parseFloat(areaMtrSqrWidth).toFixed(4);
areaMtrSqrWidth *= costMultiplier.value;
areaMtrSqrWidth = Number.parseFloat(areaMtrSqrWidth).toFixed(2);
finalCost.textContent = areaMtrSqrWidth;
finalCalculatedCost.value = (finalCost.textContent/1.2);
});
console.log(finalCalculatedCost.value);
}
calc();