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

using checkbox to set a value

Is it possible to use a checkbox to pass a value into another tag? Or do I have to use the api to check the the state of the box and use a script?
1506238764
Jakob
Sheet Author
API Scripter
It's unclear what exactly you want to do, but I'm pretty certain it can be done using sheetworkers, no API needed. 
I basically just want to check a box that if checked adds 2 to another statbox (basic attack bonus)
1506241469
Jakob
Sheet Author
API Scripter
You can do it with sheet workers, but this is so simple you can even do it via autocalc. Here's the sheet workers version (generally recommended over autocalc): <input type="checkbox" name="attr_attack_bonus_check" value="2"> <input type="number" name="attr_attack_bonus_base" value="0"> <input type="number name="attr_attack_bonus_total" value="0" readonly> <script type="text/worker"> on("change:attack_bonus_check change:attack_bonus_base", () => { getAttrs(["attack_bonus_check", "attack_bonus_base"], v => { const attrs = {}; attrs.attack_bonus_total = (parseInt(v.attack_bonus_check) || 0) + (parseInt(v.attack_bonus_base) || 0); setAttrs(attrs); }); }); </script>
1506361946
Lithl
Pro
Sheet Author
API Scripter
For something so simple, I wouldn't bother with sheet workers at all. <input type="checkbox" name="attr_attack_bonus_check" value="2"> <input type="number" name="attr_attack_bonus_base" value="0"> <input type="number" name="attr_attack_bonus_total" value="(@{attack_bonus_base} + @{attack_bonus_check})" disabled>
1506451024

Edited 1506451098
I see so the value of a checkbox is only when it is checked? That is really handy cause I also use it for the greater focuses too. Thanks guys.
1506457748
Lithl
Pro
Sheet Author
API Scripter
An unchecked checkbox's value should be '0'. A checked checkbox's value should be the value of its value  attribute, or 'on' if there is no value  attribute.
So if the default state of the checkbox is unchecked the value attribute is set to zero, correct? Regardless of what the coded value is?