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 .
×

Changing an input with a list

Hello ! I have a question and maybe you can answer it :) (i'm french so sorry for my english :p) I actually put a list to define the type of armor equiped. And right to it i have a textbox (input) disabled (it's the number of armor point depending of the type of armor..) The list ! no problem :  <select id="equip" name="attr_equip" style="width: 14em;">   <option value="01">Armor 1</option>   <option value="02">Armor 2</option>   <option value="03">Armor 3</option>   <option value="04">Armor 4</option>   <option value="05">Armor 5</option> </select> (Armor 1 have 2 armor point, armor 2 = 4 , armor 3=8 .. . . ..  ) and right to it i have this:      <input name="attr_ptsarmure" min=0 style="width: 4em;" type="number" disabled=true> How can i change the value of "attr_ptsarmure" depending of the choice of "attr_equip" Thank you for your answer :)
1591299637
GiGs
Pro
Sheet Author
API Scripter
Why not just put the armour points in the select:   <option value="2">Armor 1</option>   <option value="4">Armor 2</option>   <option value="8">Armor 3</option>   <option value="etc">Armor 4</option>   <option value="etc">Armor 5</option> If you want to do more complex stuff, you'll need to use a sheet worker. Can you describe the specifics of what you actually are doing?
1591337526

Edited 1591337598
I didn't named the armor for the example. But I have on my sheet Armor point that can be down by taking hits. When i say , you took 10 damage Il will first get done armor point instead of life. That's why i need armor point to not be in selection.
1591402010
GiGs
Pro
Sheet Author
API Scripter
By the way, you have this in your select:  <select id="equip"  ids aren't allowed in roll20 character sheets, you'll have to change that to a class. In that case the only way to do it is a sheet worker. That ay you can use the points as I sugegsted, but the armour points box can still be used to mark damage. Your HTML would need a little tweaking. You can put the points in the select options. It'll be fine. I guessed at the values.   <select class="equip" name="attr_equip" style="width: 14em;">   <option value="1">Armor 1</option>   <option value="2">Armor 2</option>   <option value="4">Armor 3</option>   <option value="8">Armor 4</option>   <option value="16">Armor 5</option> </select>  <input name="attr_ptsarmure" min=0 style="width: 4em;" type="number" value="0" readonly > Notice the change on the input - swapping disabled for readonly. Then if your html doesnt have a script block, create a section like at the end of the your sheet: <script type="text/worker"> </script> That's an empty script block. All the sheet workers you add to your sheet go between those two tags. Between those two script tags add this sheet worker: on('change: equip', function() {     getAttrs([' equip'], function(values) {             setAttrs({                   ptsarmure: parseInt(values.equip) || 0             });     }); }); Now when you change the armour type, it'll put its points in the ptsarmure box. But they aren't connected. You can apply damage to that box.
1591434289

Edited 1591434764
Thank you il will test it ! :) It works good ! thanks i will note it :)
I have another question: If i have 2 option lists, is it possible to change the value of the second list by selection on the first one ? exemple: 1st list <select class="equip" name="attr_equip" style="width: 14em;">   <option value="1">Armor 1</option>   <option value="2">Armor 2</option>   <option value="4">Armor 3</option>   <option value="8">Armor 4</option>   <option value="16">Armor 5</option> </select> 2nd list <select class="equip" name="attr_bonusequip" style="width: 14em;" disabled=true>   <option value="1">bonus str</option>   <option value="2">bonus dex</option>   <option value="4">bonus con</option>   <option value="8">Armor wis</option>   <option value="16">Armor cha</option> </select> I try this but didn't work (obviously) <script type="text/worker"> on('change:equip', function() { getAttrs(['equip'], function(values) { setAttrs({ bonusequip: (values.equip).select }); }); }); </script> I wonder if its possible to select the value of the second list by changing the first list
1591459992
GiGs
Pro
Sheet Author
API Scripter
Yes, this is easy. You're not far off. First: dont put a script block around each sheet worker. Just have one script block, and put all sheet workers inside that. This should do the trick: on('change:equip', function() { getAttrs(['equip'], function(values) { setAttrs({ bonusequip: values.equip }); }); }); However, its best to combine separate sheet workers if they are based off the same attribute. So combining the previous workers: on('change: equip', function() {     getAttrs([' equip'], function(values) {     const equip = parseInt(values.equip) || 1;             setAttrs({                  ptsarmure: equip,                 bonusequip: equip             });     }); }); Give that a try.
Mega thanks :) it help me a lot ! and yes it works ! I promise to ask you the last question >< the problem is, it's very difficult to script without (if / then /elseif etc..) Imagine  i have a numeric input (dexterity) set to 5 and numeric input (strengh) set to 5 I equip the armor giving +1 dexterity and +1 strengh. I tried many things to upgrade the bonus depending of the equiped armor (on list we see before) and when i switch armor i want those bonus to delete and put new ones. To be honest this point drive me crazy lol. with if in vb it will give something like this i think if equipbonus.value="text" then dexterity.value=dexterity.value+1 But no if :/
1591543465
GiGs
Pro
Sheet Author
API Scripter
Ask as many questions as you need - thats what the forums is for :) It will be possible to do what you want, but I need more information. How are you recording armour bonuses? How is the sheet worker to know that a particular set of bonuses are linked to a particular armour? How are you applying the bonuses to attributes? Do you have separate inputs for the base score, the armour modifier, and the total? You cant simply apply the bonus to the total of the dex or strength attribute, because there's no easy way to undo it, especially without some way of linking which bonuses come from which armour. So if you describe how these bonuses work, we can come up with something.
Actually when i change the armor (Armure), it changes the armor point right to it, and the bonuses under. I would like the bonus apply automaticly to the desired abilities. And if i change armor, i would like the bonuses to remove and the new one to apply Heres my code: List of armor and assiociated bonuses: <tr> <td class="sheet-nowrap">Armure: <select class="equip" name="attr_equip" style="width: 14em;"> <option value="0">Aucune armure</option> <option value="8">Armure de fouineur</option> <option value="12">Armure de cuir</option> <option value="20">Armure cloutée</option> <option value="25">Armure de gardien du feu</option> <option value="40">Armure de l'avant</option> </select> <input name="attr_ptsarmure" min=0 style="width: 4em;" type="number" value="0" readonly> </td> </tr> <td class="sheet-nowrap">Bonus: <select class="bonusequip" name="attr_bonusequip" style="width: auto" readonly> <option value="0">Aucun bonus</option> <option value="8">+1 Discrétion</option> <option value="12">+1 Diplomatie</option> <option value="20">+1 Intimidation</option> <option value="25">+1 Expression/Diplomatie/Contacts/Persuation/Séduction/Intimidation -1 Dextérité</option> <option value="40">+3 Intimidation</option> </select> </td> </tr> And my actual script worker: <script type="text/worker"> on('change:equip', function() { getAttrs(['equip'], function(values) { setAttrs({ ptsarmure: parseInt(values.equip) || 0, bonusequip: values.equip }); }); }); </script> and the concerned abilities box: <input name="attr_discretion" type="number" min=0 value="0"> <input name="attr_diplomatie" type="number" min=0 value="0"> <input name="attr_intimidation" type="number" min=0 value="0"> <input name="attr_contacts" type="number" min=0 value="0"> <input name="attr_persuasion" type="number" min=0 value="0"> <input name="attr_seduction" type="number" min=0 value="0"> <input name="attr_dex" type="number" min=0 value="0">