In my survey, there is a multiple-choice Question 98, which has answers: "Yes" or "No".
After the survey user typed in the answer and variable {q://QID98/ChoiceGroup/SelectedChoices} has been assigned "Yes" or "No", I want to conditionally modify its value based on a previous question, say, Question 50.
Below is a pseudocode to show what I want to achieve:
If "{q://QID50/ChoiceGroup/SelectedChoices}" == "Yes" {
{q://QID98/ChoiceGroup/SelectedChoices}="Yes" }
In other words, If Question 50 was answered "Yes", then the value of the Question 98 answer is forced to be 'Yes' (regardless of what the survey user actually typed).
If Question 50 was answered "No", then the value of the Question 98 answer will be what the survey user actually typed.
Can I use setChoiceAnswerValue and what will be the code to assign a new value to {q://QID98/ChoiceGroup/SelectedChoices} ?
I understand that what I am trying to achieve may not be the best practice , but a have a long survey and the answer to Question 98 is used in many subsequent questions and flow logic. So for me, it's much easier to modify just one Question 98 and make its answer depend on Question 50 instead of rewriting the entire survey with numerous conditional logic based on Question 98.
You can write JavaScript to automatically answer 'Yes' to Question 98 if they answered 'Yes' to Question 50 then click the Next button. Something like:
if("{q://QID50/ChoiceGroup/SelectedChoices}" == "Yes") {
jQuery("#"+this.questionId+" input[type=radio]:first").prop("checked",true);
this.clickNextButton();
}
Actually, the Question 98 is multiple-choice one with three answers: "No", "Yes", and "not sure" and Dropdown List. See the screenshot:
How will jQuery( ) code look like?
https://www.qualtrics.com/community/discussion/comment/30363#Comment_30363Assuming the choice id of Yes is 2, change the second line to:
jQuery("#"+this.questionId+" select").val("2");
I placed the code to Qualtrics.SurveyEngine.addOnload().
Correct?
Is the JS code compatible with Question 98 Validation Option "Force Response"?
I removed the condition, but the code below is not working:
neither
Qualtrics.SurveyEngine.addOnload(function()
{
jQuery("#"+this.questionId+" select").val("2");
this.clickNextButton();
});
nor
Qualtrics.SurveyEngine.addOnReady(function()
{
jQuery("#"+this.questionId+" select").val("2");
this.clickNextButton();
});
nor
Qualtrics.SurveyEngine.addOnUnload(function()
{
jQuery("#"+this.questionId+" select").val("2");
this.clickNextButton();
});
When checked in subsequent questions, ${q://QID98/ChoiceGroup/SelectedChoices} does not have any value. And display logic and validation logic do not recognize Question 98 as selected "Yes" .
So. probably, jQuery("#"+this.questionId+" select").val("2") is not working for me.
Only this.clickNextButton() does work :-)
If I remove this.clickNextButton() and keep jQuery("#"+this.questionId+" select").val("2"), should the page load with Question 98 selected as "Yes"?
Finally, I had to change question type to "Single Answer" and the below code worked for me:
Qualtrics.SurveyEngine.addOnload(function()
{
var p = "${q://QID50/ChoiceGroup/SelectedChoices}";
if( p == "Yes") {
jQuery("#"+this.questionId+" inputitype=radio]:last").prop("checked",true);
this.clickNextButton();
}
});
https://www.qualtrics.com/community/discussion/comment/30378#Comment_30378That doesn't match the order of the choices in the drop down you posted. If your choices are randomized, this approach won't work (it will only be correct about 1/3 of the time).
I changed the order as follows:
and my question type is
I have never intentionally randomized my choices (and do not know what it is).
Should my setup work correctly now?
Yes, it will work as long as Yes is always last.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.