Constant Sum question Total Show the Sum of Items selected | XM Community
Skip to main content
Solved

Constant Sum question Total Show the Sum of Items selected

  • November 15, 2018
  • 1 reply
  • 19 views

KiaResearch
Forum|alt.badge.img+1
Need some help trying to create a question that works this way... Users sees a list of items with associated prices. E.G. A $10 B $100, C $150 User can choose any combination of items they like and when they do so, the Constant Sum Total cell shows the $Total for those selected. E.G. A and B shows $110, B and C shows $260. The only way I can figure out how to do this currently, is to use the standard constant sum question w/Total and have the user type in the $ figure for each item they choose. Not horrible UX but I would prefer they just select the items using the check boxes. Any ideas or help would be most appreciated.

Best answer by TomG

You'll have to write some JavaScript... Put each price in a span with a specific class, something like: ``` A $<span class="price">10</span> B $<span class="price">100</span> etc... ``` Then any time a choice is clicked, find the selected items then within those find all the prices and add them up. Then update a total field (e.g. `<span id="total">0</span>` ) you place in the QuestionText or append to the bottom of the QuestionBody.

1 reply

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Answer
  • November 15, 2018
You'll have to write some JavaScript... Put each price in a span with a specific class, something like: ``` A $<span class="price">10</span> B $<span class="price">100</span> etc... ``` Then any time a choice is clicked, find the selected items then within those find all the prices and add them up. Then update a total field (e.g. `<span id="total">0</span>` ) you place in the QuestionText or append to the bottom of the QuestionBody.