Allowing respondents to skip constant sum questions despite 'Must Total' validation | XM Community
Skip to main content

Hi,
At my organization, we ask a lot of constant sum questions, but we also want to let our respondents skip them when they don't have the relevant data. As of now, it seems impossible to allow respondents to skip questions when 'Must Total' is selected. I think it would be ideal if the 'Must Total' validation was "activated" AFTER respondents enter ANY data into one of the constant sum boxes. So, in effect, if respondents don't enter any data, they can skip it without triggering the validation rules.
The folks over at Product Ideas suggested I post the question here. Does anyone have the custom code to make this work? Thank you in advance - I'm a newbie with javascript!
Also, I have added this request/idea to the Product Ideas page, and I've asked if they can allow the validation to be changed to 'Request Response' at a minimum or, ideally, if they can "activate" the validation as described above.
If you think this should become a standard feature, please upvote it here: https://community.qualtrics.com/XMcommunity/discussion/16460/request-response-not-force-for-constant-sum-questions/p1?new=1
Thanks,
Dr. Josh Kahn

So, you want to display the question, and allow them to skip it if they have not values to put in, right?
I can't find a work around. Looks like the answer could be to allow multiple values in the validation of the total. like "0, 100" would validate against 0 (no answers) or 100 total.
I'll give an upvote to your product idea.


Hi mklubeck, Yes, that's exactly what I am trying to do. I tried to set up validation so that if all fields were empty, then it would validate, but I couldn't get it to work. So you might be on to something with allowing multiple values to validate. Thanks for trying and for the upvote!


It surprising that ObjectiveFocus also asked this same question. While we wait for it to become a feature, here's a code you can use:
Qualtrics.SurveyEngine.addOnReady(function () {
    let quest = this,
        qc = quest.questionContainer,
        id = quest.questionId,
        total_box = qc.querySelector("#" + id + "_Total");
    total_box.oninput = function () {
        quest.disableNextButton();
        if (total_box.value == 0 || total_box.value == 100) quest.enableNextButton();
    };
});
You can change the 0 or 100 values to whatever you want.

NOTE: this will work with the constant sum question NOT with a matrix set up as a constant sum.


Thanks ahmedA
joshkahn21 and ObjectiveFocus please let us know if it works!
BTW, it's not surprising to me at all. It's a solid need so I would expect a lot of people to run into the issue. Thanks for the solution ahmedA !


mklubeck Now that you mention it, this does seem like pretty standard requirement. And when I think about it, there have been multiple surveys where I've used a screener question with display logic to accomplish this. Just didn't realize I could do it at once. Thanks.


Hi ahmedA, Thank you for your time and the code! Unfortunately, I must be doing something wrong, but I can't get it to work. When I try to advance to the next page, I get an error that I need to total the options to 100. I've tested it both in preview and after publishing the survey. I copy/pasted the code directly into the javascript code editor as in the pic posted below. Was I supposed to adjust anything? I also tried it in the code area for when the page loads, but I got the same error.
Again, many thanks for your time and code!
Josh
image.png


Remove your validation.


Yes, thank you - That was it! I had to remove the regular validation that I set up with the question originally. Thank you so much for your help!!
Best Wishes,
josh


ahmedA Very nice code! Thanks. I'm not in need of it at this time, but I added it to my Question Library for my users.


ahmedA quick question - for the quest.enableNextButton() functionality, can you help me with a simple javascript? i want to "disable" the Next Button if Question A is displayed (it has display logic), and I want to "enable" it if Question B is displayed. Only one, A or B would be displayed. So I'm assuming for each question, I can set the value to enable or disable...but I want it to do so "if displayed."
Is this easy or am I asking for too much?


mklubeck could you please ask a new question, since this isn't related to the topic being discussed. This will help others who are looking for the same solution.


Hi ahmedA , I hate to open this back up, but I am about to run a new survey next week and I just tested the code again and it doesn't seem to be working. Which, i know, is weird because i just copied the question to the new survey, and I also wrote a new question and copied the javascript code. Tried both ways, both ways don't work. There is no error message that pops up after trying to go the next page when the totals are anywhere between 1 and 99. It just lets the person advance. I went back to the original spot where it worked and now it doesn't give the error message there either. Any thoughts? I doubt anything changed on qualtrics' end. Thank you again for helping me work through this!


joshkahn21
I'm far from a "coder" but have noticed issues with javascript in the past. One being that my date widget wouldn't allow two in the same survey. The second wouldn't work. BUT before you check on that, I have to ask if you tried the regular fix...did you clear your cache and cookies?


I did not clear cookies or cache. will try that next. But i've had two people from separate computers test it and they found the same as me. If my respondents all have to clear cookies/cache for it to work, then that's not going to be a great fix.


joshkahn21 I was hoping for a simple fix...but if it's not that, and not that the JS is causing a change throughout that won't allow a second, grrr. it may not be simple? hopefully you'll hear back from ahmedA


If it's still working on the earlier question, then it implies that the problem is with the implementation and not with code/Qualtrics.
Do you have some other JS in the header/other question on the page? They maybe interfering with code.
I'll be able to comment more on it if you are able to share the preview link/QSF of the survey page.


It is not still working on the earlier question. It took me a bit before I went back and tested the earlier one because I couldn't believe it.
I set that earlier one up as a test. with one question in front of it, one after it, and the constant sum question in the middle. Happy to provide whatever you'd need, but here's the preview link for that test: https://nace.iad1.qualtrics.com/jfe/preview/SV_3CKHJUuEnLobhEa?Q_CHL=preview&Q_SurveyVersionID=current
Thanks,
josh


There is a placement issue. Delete everything in your JS editor and just keep the code that I posted earlier, it should work.


I just saw your screenshot properly, do the same thing for the previous survey also.


I tried a fresh new survey. new item. pasted it into the part that should run when page is loaded, tried that as is. then tried deleting everything in the JS editor except your code. still didn't work. Does the code work for you when you test it?


Yes. See this.
image.pngimage.png


I see, yes, it's working there. I found two problems after looking at your screenshots. 1- My next button isn't greying out like yours. 2- in the JS editor, I have an extra line of }); at the bottom of my code. and when i delete it and try to save, i get an error message that that there was an unexpected end to the code and it makes me go back and add it back before i can save and leave the JS editor.
image.png
image.png


Please ensure that the code is EXACTLY as it is shown in the screenshot.
STEP 1: Delete EVERYTHING in your JS editor.
STEP 2: Copy the code from the earlier post and paste it.


It works. Of course. Thank you.
I'll tell you where i went wrong. First, i don't know javascript. But second, i had an extra line at the top of the code that was this: Qualtrics.SurveyEngine.addOnReady(function () {
And i'm guessing that is why it wouldn't let me leave without the "extra" closing bracket.
In any case, thank you very much for trouble shooting this with me, and I apologize for wasting your time!
Many Thanks,
josh


Update: I wanted to let you all know that the code is working as intended. However, when people "skip" the question, zeroes get entered as their response because the constant sum boxes are populated by default with zeroes. When the survey is closed, this can be cleaned up relatively easily. Just wanted to let everyone know and thank ahmedA again!


Leave a Reply