0

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;
2
  • I don't understand what you're doing with the "change" variable. There's spurious math and immediate reassigns. Commented May 21, 2014 at 11:38
  • sorry, accidentially uncommented those lines Commented May 21, 2014 at 11:40

1 Answer 1

1
function calcstat(id, values) {
    var change = values - oldscores[id];
    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;
}
Sign up to request clarification or add additional context in comments.

1 Comment

im not entirely sure why my code didnt work. but this solved the problem. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.