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

Checkboxes that allow multiple boxes to be checked, stored as a string?

1620429256

Edited 1620429300
Hey, guys! I have an issue with pesky check boxes I am trying to resolve (pardon my ignorance, here; I'm kind of feeling my way through how things work). If you set a checkbox with an "attr_" value that is the same for all the input, they will swap out just like a radio button (so you can't have two of them checked at the same time). Not the behavior I want. I want them to be able to have multiple boxes checked at the same time. This can be easily accomplished with a DIFFERENT name on each checkbox's attribute name (e.g., attr_checkbox01, attr_checkbox02, etc.). But this makes a separate attribute for EVERY checkbox (Ack!). Not what I want either. What I need is a way to add the value to a single string value attribute that includes every box checked (such as "1, 7, 28" indicating that checkbox 1, 7 and 28 are checked). I have a strong feeling there is a DUH answer for this. But my searches have not turned up anything. Any suggestions.
1620458785
Richard T.
Pro
Marketplace Creator
Sheet Author
Compendium Curator
There's not a duh option, you'll need to do a sheetworker with this, something that detects when something is changed so that it can grab the appropriate attributes and combine them.  <input readonly input="text" name="attr_combined"> <input type="checkbox" name="attr_part1" value="This">This <input type="checkbox" name="attr_part2" value="Is A">Is A <input type="checkbox" name="attr_part3" value="Test">Test <script type="text/worker"> on("change:part1 change:part2 change:part3 sheet:opened", function() {     getAttrs(["part1", "part2", "part3"], function(values) {         let operation = values.part1 + values.part2 + values.part3;         setAttrs({             "combined": operation         });     }); });      </script>
Ugh. Well, guess I've got my work cut out for me. Thanks, Brian! Richard T. said: There's not a duh option, you'll need to do a sheetworker with this, something that detects when something is changed so that it can grab the appropriate attributes and combine them. 
1620486379
Andreas J.
Forum Champion
Sheet Author
Translator
Added the example to the wiki: <a href="https://wiki.roll20.net/Sheet_Worker_Snippets#Summing_up_values_based_on_multiple_checkboxes" rel="nofollow">https://wiki.roll20.net/Sheet_Worker_Snippets#Summing_up_values_based_on_multiple_checkboxes</a>
I am not sure if this will help or not but you might check out Kurt J's scriptcards which offers the ability to set up arrays.&nbsp; This would allow each item to be loaded separately yet manipulated into and out of a single string variable at need.&nbsp;&nbsp;
Thanks, Michael! That could prove useful! Michael C. said: I am not sure if this will help or not but you might check out Kurt J's scriptcards which offers the ability to set up arrays.&nbsp; This would allow each item to be loaded separately yet manipulated into and out of a single string variable at need.&nbsp;&nbsp;
Awesome! That will probably be helpful for the next guy/gal! I parused that page and a tone of others looking for a solution. 👍 Andreas J. said: Added the example to the wiki: <a href="https://wiki.roll20.net/Sheet_Worker_Snippets#Summing_up_values_based_on_multiple_checkboxes" rel="nofollow">https://wiki.roll20.net/Sheet_Worker_Snippets#Summing_up_values_based_on_multiple_checkboxes</a>