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 .
×

check checkbox if another checkbox is checked

Hey so I am making a custom character sheet for my Gamma World 2e (mutated rule set), and the issue I am having is that there is are mutations that have one bonus to Hit and a different bonus for Damage for physical attacks. My original thought process was to use 2 check boxes and have one hidden. So if you checked the one box the other would be checked automatically. So far I am able to make what I want to work in fiddle but cant make it work in roll20. So far I have this:  JSFiddle This is going to be in a repeating section for the players attacks. Any other ideas to do what I require would also be welcomed. I will say I don't feel comfortable using API. So if the aid you give uses API I will need more help then using the HTML with <script type="text/worksheet">.
1527454238
GiGs
Pro
Sheet Author
API Scripter
The jsfiddle isnt much help because it doesnt demonstrate what changes the checkboxes are meant to implement. What are the checkboxes meant to do? Using a sheetworker you can have one checkbox affect multiple stats. Something like: on("change:intuition", function() { getAttrs(["intuition"], function(values) { var checked = parseInt(values.intuition)||0; if(checked === 1) { // code to make whatever changes needed when it's checked } else { // code to make whatever changes needed when it's NOT checked } setAttrs({ "stat to change":newvalue, "another stat to change":anothernewvalue }); }); }); PS, I assume that was a  typo, but just in case, it's actually <script type="text/worker"> not worksheet.
1527458446

Edited 1527458869
I need one check box to give a "+1" to hit bonus and one to give a "+3" to damage per dice. this is the roll button that i have right now with the auto calculation:: <button type="roll" value="&{template:default} {{name=Lifter Claws}} {{attack=[[1d20+@{attkbonus}+@{intuition_hit}]]}} {{damage=[[@{DMGdice}+@{strength_MOD} + [[(@{DMGdice}>0)*@{intuition_DMG}]] ]]}}"> and it would be just more convenient to just click one checkbox then 2.  yes that was a typo I did at the end of my original message.
1527462518

Edited 1527462608
GiGs
Pro
Sheet Author
API Scripter
In that case, this should work: on("change:intuition", function() { getAttrs(["intuition"], function(values) { let checked = parseInt(values.intuition)||0; let atk = 0, dmg = 0; if(checked === 1) { atk = 1; dmg = 3; } setAttrs({ "intuition_HIT":atk, "intuition_DMG":dmg }); }); }); Note: don't use "-" in attribute names if you are going to use sheet workers, it leads to complications it's better to avoid. For this you'd need two hidden inputs as well as the single 'intuition' checkbox: <input type="hidden" class="attr_intuition_HIT"  value="0"/> <input type="hidden" class="attr_intuition_DMG"  value="0"/> PS: its probably not needed, but also change your @{intuition_hit} attribute to @{intuition_HIT} for neatness and safety.
1527465989

Edited 1527466492
Thanks so much for all your help, however the bonuses are still not being applied to the roll when I enable intuition checkbox. I saw that in the hidden inputs you use class instead of names, is this correct? This is my HTML of the Attacks Fieldset:: <fieldset class="repeating_ATTK">                     <div class="sheet-attacks">                         <div class="sheet-display">                             <button type="roll" value="&{template:default} {{name=Lifter Claws}} {{attack=[[1d20+@{attkbonus}+@{intuition_HIT}]]}} {{damage=[[@{DMGdice}+[[0d6]]+@{strength_MOD} + [[(@{DMGdice}>0)*@{intuition_DMG}]] ]]}}">                                 <span name="attr_attackname" class="attr_attackname" style="width:250px; height:20px;"></span>                             </button>                                 <input type="text" class="attr_DMGdice" name="attr_DMGdice" placeholder="DMG Dice"/>                                 <input type="number" min="0" class="attr_attkbonus" name="attr_attkbonus"  value="@{dexterity_MOD}+@{attkMOD}" disabled="true"/>                                 <input type="text" class="attr_Wtype" name="attr_Wtype" placeholder="Weapon Type"/>                                 <input type="text" class="attr_Wrange" name="attr_Wrange" placeholder="Weapons Range"/>                                 <input type="text" class="attr_Wweight" name="attr_Wweight" placeholder="5Kg/10lbs"/>                                 <input type="text" class="attr_Wsize" name="attr_Wsize" placeholder="Medium"/>                         </div><!-- Display -->                         <input class="options-flag" type="checkbox" name="attr_options-flag" checked="checked"><span>y</span>                         <div class="options">                             <div>                                   <span style="font-size:12px;">WEAPON NAME:</span><input type="text" name="attr_attackname" style="width: 120px; box-shadow: none; border:none; border-bottom:1px solid #BBBDBF;">                                       <span style="font-size:12px;">ATTACK MOD:</span><input type="text"  name="attr_attkMOD" title="More Attack Bonuses" value="0"style="width: 40px; box-shadow: none; border:none; border-bottom:1px solid #BBBDBF;text-align:center;">                             </div>                                 Intuition:<input class="attr_intuition" name="attr_intuition" type="checkbox">                                 <input class="attr_intuition_DMG" type="hidden" value="0">                                 <input class="attr_intuition_HIT" type="hidden"  value="0">                         </div>                     </div>                 </fieldset> Thank you again for all of your help.
1527467629
GiGs
Pro
Sheet Author
API Scripter
I only used class because I copied your code from the jsfiddle and didn't pay attention. I should have spotted it was using the wrong term. It should be name, not class. It's a bit late in my day, i can't check the code right now. But you can check if the names are being set by typing @{charactername|intuition_HIT} in chat, and seeing what number is reported. You can do this with each relevant stat to make sure their numebrs are accurate. Also change your intuition checkbox to this (adding a value section) just to be sure its assigning the right number when checked. Intuition:<input name="attr_intuition" type="checkbox" value="1"> Your damage code looks a bit weird to me {{damage=[[@{DMGdice}+[[0d6]]+@{strength_MOD} + [[(@{DMGdice}>0)*@{intuition_DMG}]] ]]}} But I'm a bit too sleepy to analyse it right now.
1527471845

Edited 1527476218
So I looked into my naming and such and everything seems fine, but one thing I did notice is that as soon as I add in the script you have suggested all my script doesn't work. I was able to make my previous script work by change a small piece of the script you have provided on("change:intuition", function() {     getAttrs(["intuition"], function(values) {         let checked = parseInt(values.intuition)||0;         let atk = 0, dmg = 0;         if(checked === 1); <<<-replaced the "{"     atk = 1;         dmg = 3;                  setAttrs({             "intuition_HIT":atk,             "intuition_DMG":dmg         });     }); }); As of right now its still not adding any of the values to my roll button, however if I put @{intuition_HIT} into my attkbonus auto-calculation it the +1 is always on.  As for my DMG the 0D6 is there for another mutation where the 0D6 becomes a 2d6 or a 4d6. As for this "[[(@{DMGdice}>0)*@{intuition_DMG}]]" this makes it so the 3 from intuition gets added for each dice they roll.
1527478105

Edited 1527478316
GiGs
Pro
Sheet Author
API Scripter
This bit  if(checked === 1); <<<-replaced the "{"     atk = 1;         dmg = 3; should be if(checked === 1) { atk = 1;         dmg = 3; } The starting and ending curly brackets are necessary.
Well from what I can see is that it's not changing the values from my hidden inputs. 
1527515976
GiGs
Pro
Sheet Author
API Scripter
Can you post your entire sheet and its css sheet to pastebin, and I'll check them out tonight after gaming.
Thank you so much for your help and I am sorry for taking so much of your time. Gamma World Character sheet CSS Gamma World Echo Character sheet HTML
1527616923
GiGs
Pro
Sheet Author
API Scripter
Aha, it's because the checkbox is in a repeating fieldset. I completely missed that, but it is in the snippet of cade you showed above. My bad! on("change:repeating_attk:intuition", function() {     getAttrs(["repeating_ATTK_intuition"], function(values) {         let checked = parseInt(values.repeating_ATTK_intuition)||0;         let atk = 0, dmg = 0;         if(checked === 1) {     atk = 1;             dmg = 3;         }         setAttrs({             "repeating_ATTK_intuition_HIT":atk,             "repeating_ATTK_intuition_DMG":dmg         });     }); }); I reccomend changing your attacks fieldset name to just "attacks" (lower case). Having repeating in the name isnt necessary, and having upper case letters forces you to write the script slightly differently. Notice the first 2 lines in the above script: the attk part has to be in lower case during a change event, and has to be upper case elsewhere. Better to just keep it lower case, and use a more descriptive name.
1527634854

Edited 1527634919
K thank you so much for your aid on this. I don't know how I could ever help you, but if you need my aid don't be stranger.
1527640520
GiGs
Pro
Sheet Author
API Scripter
Thanks, i'm touched. I'm just glad to have been able to help.