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

Assistance Requested: Select Option Output Text (option_user_selection)

1494426042
Axel
Pro
Sheet Author
I have a problem I'd like some advice on. I need a way to get the text from an option tag, not just the value.&nbsp; I saw a discussion about somelike like it here:&nbsp; <a href="http://stackoverflow.com/questions/4641962/getting-an-option-text-value-with-javascript" rel="nofollow">http://stackoverflow.com/questions/4641962/getting-an-option-text-value-with-javascript</a> Unfortunately I'm not proficient with javascript and I don't know if it will work in a Roll20 character sheet in any case. What I have is something like this: &lt;select name="attr_actionmod"/&gt; &lt;option value="0" selected="selected"&gt;Stat?&lt;/option&gt; &lt;option value="@{strmod}"&gt;STR&lt;/option&gt; &lt;option value="@{dexmod}"&gt;DEX&lt;/option&gt; &lt;option value="@{conmod}"&gt;CON&lt;/option&gt; &lt;option value="@{intmod}"&gt;INT&lt;/option&gt; &lt;option value="@{wismod}"&gt;WIS&lt;/option&gt; &lt;option value="@{chamod}"&gt;CHA&lt;/option&gt; &lt;/select&gt; &lt;button type="roll" name="roll_Test" value="&{template:test} {{rollname=@{actioname}}} {{charname=@{character_name}}} {{stat=[[ option_user_selection ]]}} {{roll=[[2d6 + @{actionmod}]]}}"&gt;&lt;/button&gt; What I need is for the "stat" property of the template to output the text of the option the user selected, i.e. "STR" or "DEX", etc. If this is possible, how would I accomplish it? Detailed advice will be greatly appreciated.
1494436782

Edited 1494436945
Lithl
Pro
Sheet Author
API Scripter
You can use JavaScript in your character sheet via sheet worker scripts. However, sheet workers are sandboxed and don't have access to the DOM, so you can't use the linked StackOverflow answer to get what you want. I would recommend something like this: &lt;select name="attr_statname"&gt; &lt;option value="" disabled selected hidden&gt;Stat?&lt;/option&gt; &lt;option value="STR"&gt;STR&lt;/option&gt; &lt;option value="DEX"&gt;DEX&lt;/option&gt; &lt;option value="CON"&gt;CON&lt;/option&gt; &lt;option value="INT"&gt;INT&lt;/option&gt; &lt;option value="WIS"&gt;WIS&lt;/option&gt; &lt;option value="CHA"&gt;CHA&lt;/option&gt; &lt;/select&gt; &lt;input type="hidden" name="attr_actionmod" value="0"&gt; &lt;button type="roll" name="roll_Test" value="&{template:test} {{rollname=@{actioname}}} {{charname=@{character_name}}} {{stat=@{statname}}} {{roll=[[2d6 + @{actionmod}]]}}"&gt;&lt;/button&gt; &lt;script type="text/worker"&gt; // trigger when the sheet is opened for the first time in a session or @{statname} changes on('sheet:opened change:statname', () =&gt; { getAttrs(['statname'], (values) =&gt; { // convert "STR" to "strmod" const actionmodAttrName = `${values.statname.toLowerCase()}mod`; getAttrs([actionmodAttrName], (values) =&gt; { // set the value of @{actionmod} to the value of @{strmod} setAttrs({actionmod: values[actionmodAttrName]}); }); }); }); &lt;/script&gt;
1494488084

Edited 1494494678
Axel
Pro
Sheet Author
This is great! Thanks! Can this work within a repeating fieldset? Edit: I'm guessing not.
1494521002

Edited 1494521018
Lithl
Pro
Sheet Author
API Scripter
You should be able to use it in a repeating section, the JavaScript would just have to be slightly different. This ought to work: on('change:repeating_actions:statname', () =&gt; { getAttrs(['repeating_actions_statname'], (values) =&gt; { // convert "STR" to "strmod" const actionmodAttrName = `${values.repeating_actions_statname.toLowerCase()}mod`; getAttrs([actionmodAttrName], (values) =&gt; { // set the value of @{actionmod} to the value of @{strmod} setAttrs({repeating_actions_actionmod: values[actionmodAttrName]}); }); }); });
1494579418
Axel
Pro
Sheet Author
This works perfectly! Thank you kindly good sir!