Validation to add the sum of 3 text boxes in multiple choices question to be 100 | XM Community
Skip to main content

Validation to add the sum of 3 text boxes in multiple choices question to be 100

  • December 2, 2022
  • 10 replies
  • 1332 views

Forum|alt.badge.img+6

I need help with validation on a multiple-choice question.
The question has 4 options. The sum of options 1, 2, and 3 should make a sum of 100. If not, an error box should pop up stating the sum of 1,2,3 should be 100. If the user chooses, option 4, then he can proceed to the next question. I tried the Constant Sum option but I suppose, having the 4th option is not viable here.
Ques: Please use percentages that make a 100% of financial investment activities:

  1. Mutual Funds (Text box)

  2. Insurance (Text box)

  3. Fixed Deposit (Text box)

  4. Approximately Equal across all 

Please provide an insight on how to do this using validation or javascript.
Thank you.


10 replies

Forum|alt.badge.img+6
  • Author
  • QPN Level 2 ●●
  • 27 replies
  • December 2, 2022

TomG Can you help


Deepak
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+46
  • 1555 replies
  • December 2, 2022

Forum|alt.badge.img+6
  • Author
  • QPN Level 2 ●●
  • 27 replies
  • December 2, 2022

Deepak Thank you for the above thread.
My doubt now is:
If I use Side by side type of question, I can't use the 4th option 'Approximately Equal across all', right?


Deepak
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+46
  • 1555 replies
  • December 2, 2022

https://community.qualtrics.com/XMcommunity/discussion/comment/52776#Comment_52776Arunaj91 What you can do is create another multiple choice question hide the question text with CSS and it could look something like this then you can apply custom validation on the question you create that if the above question is filled and this is checked it should show an error. Also if the above is filled and statement 4 is not 100 then error.
image.png
Hope it helps!


bstrahin
Level 6 ●●●●●●
Forum|alt.badge.img+38
  • Level 6 ●●●●●●
  • 649 replies
  • December 2, 2022

You can make this simpler on yourself by splitting it into two questions.
Q1 is your screener: "Are your financial activities approximately equal between mutual funds, insurance, and fixed deposits?"
Yes/No

Your next question is a constant sum question with options for mutual funds, insurance and fixed deposit. Use in page display logic to show the constant sum question if Q1=No. Use the constant sum validation to ensure the total is 100.

image.png
image.png



bstrahin
Level 6 ●●●●●●
Forum|alt.badge.img+38
  • Level 6 ●●●●●●
  • 649 replies
  • December 2, 2022

https://community.qualtrics.com/XMcommunity/discussion/comment/52781#Comment_52781Deepak and Arunaj91 this is where I started before flipping the recommended order. I couldn't find in custom validation an easy way cross validate the questions and use the total of the constant sum in that (it lets us use values for the individual rows which could be problematic if any row should be zero).


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6083 replies
  • December 3, 2022

Arunaj91,
Here is one way to do it:
1) A constant sum question with your three categories followed by a multi-select MCQ with one choice: 'Approximately equal'
2) Add this JS to the MCQ to make it look part of the constant sum:
Qualtrics.SurveyEngine.addOnload(function() {
var q = jQuery(this.questionContainer);
q.prev().hide();
q.find(".QuestionText").hide();
});
3) Add custom validation to the constant sum something like:
Q1 Mutual Funds Is Equal to $e{ 100 - q://QID1/ChoiceNumericEntryValue/2 - q://QID1/ChoiceNumericEntryValue/3 }
Or Q2 Approximately equal Is Selected
Where Q1 is the constant sum and Q2 is the MCQ. Replace QID1 with the actual QID of your constant sum question.
An alternative, more complex solution would be to use JS automatically calculate and populate the constant sum amounts when 'Approximately equal' is checked and uncheck 'Automatically equal' when text is entered in the constant sum. The advantage would be that your data would all be contained in the constant sum question. If you did that you could use standard Must Total 100 validation on the constant sum.





Forum|alt.badge.img+6
  • Author
  • QPN Level 2 ●●
  • 27 replies
  • December 6, 2022

TomG If the above method is applied, wouldn't it be difficult if the participant enters the value in Constant sum and clicks on MCQ? The Survey responses file would have both data filled in, right?


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6083 replies
  • December 6, 2022

https://community.qualtrics.com/XMcommunity/discussion/comment/52907#Comment_52907Yes, they would both have data. You could add a bit of JS to blank the constant sum when Approximately equal is checked.


Forum|alt.badge.img+6
  • Author
  • QPN Level 2 ●●
  • 27 replies
  • December 12, 2022

Thank You All for the answers :)