When i change the values on the number input boxes depending on if the value increases or decreases its supposed to change the "total" according to if it was increased or decreased (its spending the total points)
however when i change between "9" and "10" it reverses (if i lower the number it also lowers the total, and vice versa, when its supposed to do the opposite)
site for testing: http://alboneon.pentacore.se/ you'll have to log in so Username: stackoverflow and password: 1234 and then reach it by pressing create character
Input boxes:
<div style="width: 45%;right: 0; float: right; padding-right: 10px; text-align: right;">
<!--<button onchange="calcstat()">Randomize</button>-->Stat <br/>
<input id="strcrt" type="number" max="15" min="8" value="8" onchange="calcstat(this.id, this.value)"><br/>
<input id="dexcrt" type="number" max="15" min="8" value="8" onchange="calcstat(this.id, this.value)"><br/>
<input id="concrt" type="number" max="15" min="8" value="8" onchange="calcstat(this.id, this.value)"><br/>
<input id="intcrt" type="number" max="15" min="8" value="8" onchange="calcstat(this.id, this.value)"><br/>
<input id="wiscrt" type="number" max="15" min="8" value="8" onchange="calcstat(this.id, this.value)"><br/>
<input id="chacrt" type="number" max="15" min="8" value="8" onchange="calcstat(this.id, this.value)"><br/>
<div id="total">27</div>
</div>
Javascript:
function calcstat(id, values) {
var change = 0 * 1;
if (oldscores[id] < values) {
//change = values - 8;
change = 1 * 1;
} else if (oldscores[id] > values) {
//change = -Math.abs(oldscores[id] - 8);
change = change-1;
}
atributescore = atributescore - change;
oldscores["strcrt"] = document.getElementById("strcrt").value;
oldscores["dexcrt"] = document.getElementById("dexcrt").value;
oldscores["concrt"] = document.getElementById("concrt").value;
oldscores["intcrt"] = document.getElementById("intcrt").value;
oldscores["wiscrt"] = document.getElementById("wiscrt").value;
oldscores["chacrt"] = document.getElementById("chacrt").value;
document.getElementById("total").innerHTML = atributescore;