Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

html help

1490408227

Edited 1490408360
I tried asking this before, but I didn't explain what I meant well enough so I'll try again I have an input with the name "inputA" I also have 3 possible outputs named "outputA", "outputB", "outputC" I want the user to be able to put a number into the input field, and use a select to pick an output. The value of the selected output would then be set to the input value. For example: You enter 5 into the input. "inputA" is not 5, you then select "outputB" using the select field. Now, outputB also equals 5, but outputA and outputC equal 0. If you change your selection to outputC, then outputA and outputB will become 0 and outputC will become 5.
I could be wrong, but I don't see a way to do this without a sheet worker. The tools and autocalc fields available to the standard sheet don't allow for something like this. Regarding a sheet worker, I can't make head's or tails of them, but there are a few blooded wizards among us who I'm sure can point out what to do :)
1490413244

Edited 1490413298
This was my first attempt, but nothing happened... <div class="sheet-row sheet-grey-row"> <div class="sheet-col-1-2"><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> <script type="text/worker"> on("change:test1", function() { if(test1==1){ itemstrength_mod1=test2; } else if(test1==2){ itemdexterity_mod1=test2; } else if(test1==3){ itemconstitution_mod1=test2; } else if(test1==4){ itemintelligence_mod1=test2; } else if(test1==5){ itemwisdom_mod1=test2; } else { itemcharisma_mod1=test2; }  }); </script> </div>
Still not sure what I'm doing wrong...
1490433357
Finderski
Pro
Sheet Author
Compendium Curator
I'm not the guy to help with the sheet worker (because I struggle to get them to work, myself), but you are missing the getAttrs() to read in the value of test1; you'd also need to getAttrs for test2 if you're going to use that in the script to set the value of something to that. Also, be aware when you use getAttrs, the values come in as a string and NOT as an integer. Your above code is checking against integers. That means you'll either need to cast the values as integers OR check against string values (i.e. if (test.value === '1')...). Lastly, to set the value of item*_mod1 to test2, you'll need to use setAttrs. For more info on sheet workers, check out the  wiki .
1490457504

Edited 1490457642
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>
Wait, wait, wait, you can use switch!? Did I somehow miss the part in the script worker page where it said you can you any Javascript within the script field? 
Just realized my intro above might cause confusion: When I say "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," I mean the part about it displaying is not required. The attributes themselves still need to exist on your sheet somewhere, even as hidden fields.
I understood that part. I'm just realizing that this entire time, I could have used more complex javascript and saved myself 2 headaches. Damnit all... it was the first sentence and I assumed the examples on the page were the only options available. I think I'm going to go cry.
1490470902

Edited 1490470927
In case you have not thought of it, I read over the HTML and Sheet Worker code for other sheets, even for games I do not play, to see examples of what is possible and how to do things. It may seem frustrating to find out you could have had an easier way, but better to learn now than later, or never!
I am so insanely grateful for what you have done. I come from a java/C# (object oriented) background and html is so very not that. So just knowing I can use javascript is like realizing there was a nailgun when I need to put in 5000 nails and had been using a hammer.
1490474484
Lithl
Pro
Sheet Author
API Scripter
Peter W. said: Did I somehow miss the part in the script worker page where it said you can you any Javascript within the script field?  Not any ; the sheet workers are sandboxed and don't have access to the DOM. But most .