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

Need Help w/ Auto-Populating Text Fields

1503760563

Edited 1503761160
So, I've been creating a new character sheet for a game that some of my friends and I are developing. The sheet has been coming along nicely thus far but I've run into a speed bump. I am new at programming all together but I think I understand the basics of HTML and CSS. Let me tell you the problem I'm stuck on. I have a select option list right now that I want to auto-populate other fields on the sheet. I know this is possible somehow but I don't have any knowledge of APIs or Sheet Worker Scripts. Let me provide my current code for the select options. <code> <select name="attr_disease1"> <option value="None">None</option> <option value="Bronchitis">Bronchitis</option> <option value="The Flu">The Flu</option> <option value="Fungal Pneumonia">Fungal Pneumonia</option> <option value="Mild Cholera">Mild Cholera</option> <option value="Sleepers Curse">Sleeper's Curse</option> <option value="Spore Anemia">Spore Anemia</option> <option value="Succubus Virus">Succubus Virus</option> <option value="Succubus Virus">Other</option> </select> </code> There are three fields that I want to be populated depending on the response; I need a text input that tells the symptoms of the disease selected, another one that tells the advancement of the disease, and one more that states the cure. Any help on making this happen would make my day/week.
1503766045

Edited 1503766304
Jakob
Sheet Author
API Scripter
Yeah, so you definitely need to use sheet workers for this. First, in the html, add some (readonly, if you don't want the user to change these) inputs that show your symptoms, advancement, cure (you can also use spans if you don't want these values to look like inputs). <input name="attr_disease1_symptoms" type="text" readonly> <input name="attr_disease1_advancement" type="text" readonly> <input name="attr_disease1_cure" type="text" readonly> Then, you need to add a sheet worker script that sets these three fields whenever disease1 changes. Something like this. All the symptoms, advancement, cures are stored in the diseaseData object. <script type="text/worker"> "use strict"; const diseaseData = {   "None": {     symptoms: "None",     advancement: "None",     cure: "None needed"   },   /* ... and so on, add data for other diseases here */   "Other": {     symptoms: "specific",     advancement: "specific",     cure: "specific"   } }; on('change:disease1', () => {   getAttrs(['disease1'], values => { // Get our disease. Default to Other if it's not on the list     const disease = diseaseDictionary[values.disease1] || diseaseDictionary.Other;     setAttrs({       disease1_symptoms: disease.symptoms,       disease1_advancement: disease.advancement,       disease1_cure: disease.cure     });   }); }); </script>
Thanks, I actually just got it figured out. Apparently, another sheet author was trying to do the same thing. Thanks for the help. Forum mods can close this thread. I'll post the code for other authors looking to do the same thing first though. What tag am I supposed to use for posting code?