Is there a way to set the Value of currentIndex to always be 0?
The calculation of (CRANK1 + CRANK2) + (DRANK1 + DRANK2) should result in (0 + selected amount), but it is currently calculating as (selected amount + selected amount).
Any assistance would be greatly appreciated. Thank you. MOSTLY CODE IN POST, NEED TEXT MOSTLY CODE IN POST, NEED TEXT MOSTLY CODE IN POST, NEED TEXT
var current_division,
desired_division;
var prices = [
00,09,09,09,09,
12,12,14,14,14,
17,17,17,17,19,
23,24,25,28,28,
35,40,50,65,85,
120,00,00,00,00
];
function getCurrentIndex() {
return (+document.getElementById("CRANK1").value +
+document.getElementById("CRANK2").value);
}
function getDesiredIndex() {
return (+document.getElementById("DRANK1").value +
+document.getElementById("DRANK2").value);
}
function total() {
var currentIndex = getCurrentIndex();
var desiredIndex = getDesiredIndex();
if (desiredIndex < currentIndex) {
document.getElementById('prices').value = "You can't rank backwards";
return;
}
var accumulatedPrice = 0;
for(var i = currentIndex; i <= desiredIndex; i++) {
accumulatedPrice += prices[i];
}
document.getElementById('prices').value = accumulatedPrice;
document.getElementById("prices").readOnly = true;
}
document.getElementById('divboost').addEventListener('change', function() {
total();
})
HTML
<form id="divboost" name="priceCalc" action="">
<br/>
<select id="CRANK1"> Current Rank
<option value="0">Bronze</option>
<option value="5">Silver</option>
<option value="10">Gold</option>
<option value="15">Platinum</option>
<option value="20">Diamond</option>
</select>
<br>
<br/>
<select id="CRANK2"> Current Divison
<option value="0">Division 5</option>
<option value="1">Division 4</option>
<option value="2">Division 3</option>
<option value="3">Division 2</option>
<option value="4">Division 1</option>
</select>
<br>
<br>
<br/>
<br/>
<select id="DRANK1"> Desired Rank
<option value="0">Bronze</option>
<option value="5">Silver</option>
<option value="10">Gold</option>
<option value="15">Platinum</option>
<option value="20">Diamond</option>
<option value="25">Master</option>
</select>
<br>
<br/>
<select id="DRANK2"> Desired Divison
<option value="0">Division 5</option>
<option value="1">Division 4</option>
<option value="2">Division 3</option>
<option value="3">Division 2</option>
<option value="4">Division 1</option>
</select>
<br>
<br>
€ <input type="text" id="prices">
<br/>
<br>
</form>