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

Get the text from a select tag

1426613383
Kryx
Pro
Sheet Author
API Scripter
Is it possible to get the value of the text or anything like "rel" from a select's option tag? Here is my select: <select name="attr_acrobatics_attribute"> <option value="@{strength_mod}">Str</option> <option value="@{dexterity_mod}" selected>Dex</option> <option value="@{constitution_mod}">Con</option> <option value="@{intelligence_mod}">Int</option> <option value="@{wisdom_mod}">Wis</option> <option value="@{charisma_mod}">Cha</option> </select> It allows the user to change the attribute used on the fly for skill checks. I'd like to be able to display the selected text (ex: "Dex") when I use the roll template. I currently use: {{title=Acrobatics (Dex)}} in my 5e template. I'd like to inject Dex in there. I could do it if I had access to javascript - just read the text of the selected option. Is it possible to do since we don't have access to JS? Maybe a hidden input whose value is equal to that text? Thanks
1426674620
Kryx
Pro
Sheet Author
API Scripter
Another option: <div> <select name="attr_test_attribute"> <option value="strength">Str</option> <option value="dexterity">Dex</option> <option value="constitution">Con</option> <option value="intelligence">Int</option> <option value="wisdom" selected="selected">Wis</option> <option value="charisma">Cha</option> </select> </div> <div> <input type="input" name="attr_weeeee" value="@{test_attribute}_mod" disabled="disabled" /> <input type="input" name="attr_weeeee" value="@{@{test_attribute}_mod}" disabled="disabled" /> </div> But that doesn't work for the obvious reason of trying to parse "test_attribute" and then @{@{test_attribute}_mod} when in reality they are parsed at the same time. Any ideas?
1426675349
Finderski
Plus
Sheet Author
Compendium Curator
Is this for a standard sheet or a custom character sheet? If it's for a custom one, could you use the API (since it looks like you're a mentor)?
1426678170
Kryx
Pro
Sheet Author
API Scripter
I'd like other to be able to use it. I assume that is standard and prevents API usage?
1426678502
Lithl
Pro
Sheet Author
API Scripter
No, there isn't any means of grabbing the <option>'s text node. Obviously you can set the text and the value to be the same thing, but that's not what you're looking for.
1426682522
Kryx
Pro
Sheet Author
API Scripter
Ya, I'm looking to use the modifier for the roll and then the label for displaying, but it seems it's not technically possible w/o the API which would prevent others from using it. Sad - I'll just not display the value then.
1427001670
Chad
Sheet Author
I'd love to see this be possible as well :( Trying to find a workaround at this time actually. Anyone have any luck? I was able to find a workaround for using some calculated formulas in dice rolls that otherwise would not work... maybe there is one for this.
1427012741
Lithl
Pro
Sheet Author
API Scripter
Chad said: I'd love to see this be possible as well :( Trying to find a workaround at this time actually. Anyone have any luck? I was able to find a workaround for using some calculated formulas in dice rolls that otherwise would not work... maybe there is one for this. Steve posted a solution in another thread that works if you're trying to put the stuff into a roll template (but not otherwise). <select name="attr_example"> <option value="{{example value=1}} {{example text=One}}">One</option> <option value="{{example value=2}} {{example text=Two}}">Two</option> <option value="{{example value=3}} {{example text=Three}}">Three</option> </select> <button name="roll_example-roll" value="&{template:example-template} {{name=Foo}} {{roll=[[3d8+6]]}} @{example}"></button>
1427018110

Edited 1427021569
Kryx
Pro
Sheet Author
API Scripter
That only works if your select goes directly to the roller. It doesn't if your select feeds another input that is used by a roll button. :( EDIT: Actually it may work.. is what I get with the following code: <select name="attr_acrobatics_attribute" class="sheet-skills-attribute-selector"> <option value="{{acrobatics_attribute value=@{strength_mod} }} {{acrobatics_attribute text=Str}}">Str</option> <option value="{{acrobatics_attribute value=@{dexterity_mod} }} {{acrobatics_attribute text=Str}}" selected="selected">Dex</option> <option value="{{acrobatics_attribute value=@{constitution_mod} }} {{acrobatics_attribute text=Str}}">Con</option> <option value="{{acrobatics_attribute value=@{intelligence_mod} }} {{acrobatics_attribute text=Str}}">Int</option> <option value="{{acrobatics_attribute value=@{wisdom_mod} }} {{acrobatics_attribute text=Str}}">Wis</option> <option value="{{acrobatics_attribute value=@{charisma_mod} }} {{acrobatics_attribute text=Str}}">Cha</option> </select> <input type="number" name="attr_acrobatics_value_test" value="0 + @{acrobatics_attribute}" disabled="disabled"> <button type="roll" name="roll_Acrobatics_Check_test" value="@{output_option} &{template:5eDefault} {{ability=1}} {{title=Acrobatics (Dex)}} {{subheader=@{character_name}}} {{subheaderright=Ability check}} {{rollname=Result}} {{roll= @{acrobatics_attribute text} }} {{rolladv=[[ 1d20 + @{acrobatics} + (@{global_check_bonus}) ]]}} @{acrobatics_attribute} @{classactionacrobatics}"></button> The input still grabs the value which is great! However on the roll template side I need to split text from value. Can I extract the value from the text and pass them as 2 different items to the template? Is there a way to do that? Right now it's all wrong.