Displaying Words Based on Checkbox Selection
Jun 16, 2020
By
Brian McCann
I'm struggling with the logic of how to build a slide. I have 9 options to describe how someone feels about a situation. They can select 0-9 options via the checkbox next to each word (confused, angry, frustrated, happy, etc). If they selected the check boxes for angry, confused, and happy, on the next slide I want it to say 'You felt angry, happy, confused' . A different learner may have selected only confused and angry, so I'd want it to say for them "You felt confused and angry."
Does anyone have a suggestion of how to pull this off? The few options I'm considering seem very convoluted and complex and before I go down those routes, I'm hoping the brilliant minds on here can help me out. Thank you!
4 Replies
Hi Brian, I understand the problem you have. Storyline doesn't provide any concatenation of variable values. When I have had to do this, I have relied on JavaScript to concatenate the variable values and then feedback the concatenated values to a Storyline variable.
In your case, I would have a variable for each of your 0-9 options (e.g opt0, opt1, opt02 etc) and assign the variables the values of the check boxes if they are selected.
I would then use a JavaScript function to concatenate the values and assign to a new variable. If we have a Storyline variable called "concattext" our JavaScript might look something like this.
You could modify the JS a bit more so that you insert a comma instead of " and " if there are more that two options selected. You could have another storyline variable that passes that information.
Hi Sam. Thank you for the response! I really appreciate you including the JS snippet. That did the trick and is so much easier and faster than what I'd been considering. THANK YOU!
If you care to share more, what would that second JS look like to include commas, rather than just Ands?
Something like the above. Warning, not tested though. You'd need an SL variable tracking the number of options selected so the script can access it to determine where commas and the final "and" sit.
This is a great spot for me to start. I really appreciate your help! Thank you so much, Sam!
This discussion is closed. You can start a new discussion or contact Articulate Support.