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

Hide/Show Divs Based on Number Field

Is the only way to do this with checkboxes?  Or can you do it based on a value?  For example, have a number field that has values from 1 to 5.  Based on the value, there are up to 5 divs that I want to show or hide.  So if the value is 2, I show div #1 and div #2.  If the value is 5, I show all 5 divs.   I tried using repeating fieldsets, but that appears to be buggy at the moment in Chrome.   Plus I don't want the user to be able to add or remove from the list.  It needs to be based on the value in the number field.
1506486966

Edited 1506487069
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You'll need a sheetworker, but should be totally doable. Here's some theoretical code (may need to correct it): HTML <input class='div-show-input' name='attr_div_show_input' type='number'> <input class='div-show-radio' name='attr_div_show_radio' type='radio' value='0' checked='checked'> <input class='div-show-radio div-show-1' name='attr_div_show_radio' type='radio' value='1'> <input class='div-show-radio div-show-2' name='attr_div_show_radio' type='radio' value='2'> <input class='div-show-radio div-show-3' name='attr_div_show_radio' type='radio' value='3'> <div class='conditional-div show-1'> Content 1 </div> <div class='conditional-div show-2'> Content 2 </div> <div class='conditional-div show-3'> Content 3 </div> CSS .sheet-conditional-div, .sheet-div-show-radio{ display:none; } .sheet-div-show-1:checked ~ .sheet-show-1{ display:initial; } .sheet-div-show-2:checked ~ .sheet-show-1, .sheet-div-show-2:checked ~ .sheet-show-2{ display:initial; } .sheet-div-show-3:checked ~ .sheet-show-1, .sheet-div-show-3:checked ~ .sheet-show-2, .sheet-div-show-3:checked ~ .sheet-show-3{ display:initial; } Sheetworker on('change:div_show_input',(event)=>{ getAttrs(['div_show_input'],(objs)=>{ let setObjs={}; setObj['div_show_radio']=Math.max(objs['div_show_input']*1||0,3); setAttrs(setObj,{silent:true}); }); }); I've only done it out to 3 divs, but should be enough to get the idea. Edited for typos.
I'll give it a try.  Thanks!