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

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.


TomG Can you help


https://community.qualtrics.com/XMcommunity/discussion/23212/validation-to-add-the-sum-of-3-text-boxes-in-multiple-choices-question-to-be-100The following thread should help you it is for side by side so you will have to modify a bit
Summing total of 100% in a text entry Side by Side Question — XM Community (qualtrics.com)
Hope it helps!


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?


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!


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



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).


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.





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?


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.


Thank You All for the answers 🙂


Leave a Reply