Dynamically Updating Bars on Constant Sum Question | XM Community
Skip to main content

Hello,
I have a multipart survey where, in Part 1, I ask people to divide 100 tasks between Part 2 and Part 3. I'm currently using a "Constant Sum" question:
constantSum.PNGI'd like to add some Javascript code that would do the following:
When a person clicks a bar, the other bar (e.g., the one not clicked) dynamically updates to the amount such that the total number of tasks between the two bars is 100. E.g., suppose a person clicked on the Part 2 bar at the value 57. Currently, this is what it shows:
constantSum2.PNGInstead, I'd like the Part 3 bar to update automatically to 43. Similarly, if I clicked on, say, 80 on the Part 3 bar, I'd like the Part 2 bar to update to 20. And so on.
I know the following code captures the value of each bar (whenever someone clicks one of the two):
codeConstantSum.PNGHowever, the code is missing two crucial elements. First, while I know how to capture/record the value when a bar is clicked, I don't know how to set a particular bar value. Second, the current code can only register if a person clicked either of the two bars. I need to differentiate which bar was clicked, so I know to change the other bar's value.
I feel like this is straightforward and must have been asked on the forum, but I can't seem to find it. Any tips/pointers are much appreciated!
-David

Check this post


Thank you, this is perfect!


Leave a Reply