I flail my way through JavaScript with much help from forum gurus like
TheAaron and Brian, but this seems to work. One of those more gifted
coders may come along and condense this code into a shorter and more
efficient form (there's probably a way to make a loop to go through the SetAttrs rather than the brute force way I do it below). Note that I added a display of the ability mod field so
you can see that it changes, but it is not required for the function. <div class="sheet-row sheet-grey-row">
<div class="sheet-col-1-2">Item Mod: <input type="number" name="attr_test2" value="0" min="0" step="1"></div>
<div class="sheet-col-1-2 sheet-core-stat-label">
<select name="attr_test1">
<option value="1" selected="selected">STR</option>
<option value="2">DEX</option>
<option value="3">CON</option>
<option value="4">INT</option>
<option value="5">WIS</option>
<option value="6">CHA</option>
</select>
</div>
</div>
<div class="sheet-col-1-2">STR Mod: <input type="number" name="attr_itemstrength_mod1" value="0" readonly="readonly"> </div>
<div class="sheet-col-1-2">DEX Mod: <input type="number" name="attr_itemdexterity_mod1" value="0" readonly="readonly"> </div>
<div class="sheet-col-1-2">CON Mod: <input type="number" name="attr_itemconstitution_mod1" value="0" readonly="readonly"> </div>
<div class="sheet-col-1-2">INT Mod: <input type="number" name="attr_itemintelligence_mod1" value="0" readonly="readonly"> </div>
<div class="sheet-col-1-2">WIS Mod: <input type="number" name="attr_itemwisdom_mod1" value="0" readonly="readonly"> </div>
<div class="sheet-col-1-2">CHA Mod: <input type="number" name="attr_itemcharisma_mod1" value="0" readonly="readonly"> </div>
<script type="text/worker">
on("sheet:opened change:test1 change:test2", function() {
getAttrs(["test1", "test2", "itemstrength_mod1", "itemdexterity_mod1", "itemconstitution_mod1", "itemintelligence_mod1", "itemwisdom_mod1", "itemcharisma_mod1"], function(value) {
switch(value.test1) {
case "1": //STR
setAttrs({
"itemstrength_mod1": value.test2,
"itemdexterity_mod1": "0",
"itemconstitution_mod1": "0",
"itemintelligence_mod1": "0",
"itemwisdom_mod1": "0",
"itemcharisma_mod1": "0"
});
break;
case "2": //DEX
setAttrs({
"itemstrength_mod1": "0",
"itemdexterity_mod1": value.test2,
"itemconstitution_mod1": "0",
"itemintelligence_mod1": "0",
"itemwisdom_mod1": "0",
"itemcharisma_mod1": "0"
});
break;
case "3": //CON
setAttrs({
"itemstrength_mod1": "0",
"itemdexterity_mod1": "0",
"itemconstitution_mod1": value.test2,
"itemintelligence_mod1": "0",
"itemwisdom_mod1": "0",
"itemcharisma_mod1": "0"
});
break;
case "4": //INT
setAttrs({
"itemstrength_mod1": "0",
"itemdexterity_mod1": "0",
"itemconstitution_mod1": "0",
"itemintelligence_mod1": value.test2,
"itemwisdom_mod1": "0",
"itemcharisma_mod1": "0"
});
break;
case "5": //WIS
setAttrs({
"itemstrength_mod1": "0",
"itemdexterity_mod1": "0",
"itemconstitution_mod1": "0",
"itemintelligence_mod1": "0",
"itemwisdom_mod1": value.test2,
"itemcharisma_mod1": "0"
});
break;
default: //CHA
setAttrs({
"itemstrength_mod1": "0",
"itemdexterity_mod1": "0",
"itemconstitution_mod1": "0",
"itemintelligence_mod1": "0",
"itemwisdom_mod1": "0",
"itemcharisma_mod1": value.test2
});
}
});
});
</script>