First off thank you everyone for your help with my previous question. I made my code do exactly what I wanted it to do with your help. But now it's also doing something I don't want it to do.
function raceMod() {
var race = document.getElementById("race").value;
var str = document.getElementById("strScore").value;
if (race == "orc") {
var orc = {
str: 4,
dex: 0,
con: 0,
int: -2,
wis: -2,
cha: -2
}
document.getElementById("strScore").value = (parseInt(str) + parseInt(orc.str))
} else if (race == "ore") {
var ore = {
str: 2,
dex: 0,
con: 0,
int: 0,
wis: 2,
cha: -2
};
document.getElementById("strScore").value = (parseInt(str) + parseInt(ore.str))
}
}
This is my javascript. I have a drop down menu of potential races to pick from. Depending on the race chosen different variable are created that affect the text input that corresponds with that variable.
Right now the user inputs a number into the text input and then selects a race. Depending on the race selected a modifier is added or subtracted from the numbers the user has already entered.
The problem that I'm having is the script continues to add to the input even if has already been modified.
For instance if the user types in "10" to the input and selects Orc the 10 is turned into a 14. But then if he selects a Oread ("ore") the input changes to 16. I need it to change to 12. Essentially I need the javascript to ignore the new number and only add the variable to the original input.
Is there anyway to do this?
Aucun commentaire:
Enregistrer un commentaire