Prepopulate a multiple response question | XM Community
Skip to main content
Solved

Prepopulate a multiple response question


Forum|alt.badge.img+2

I know there is code to do this 

                jQuery('input[type="checkbox"]').eq(0).prop('checked',true);

but this doesn’t work if the multiple response question is randomised. As it just puts it into the first option that appears rather than option 1.

SetChoiceValue doesn’t seem to work either only works for single response.

 

Is there code to reference the actual option code?

 

 

 

Best answer by TomG

jQuery('input[choiceid=1]').prop('checked',true);

 

View original

5 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5938 replies
  • Answer
  • April 9, 2024
jQuery('input[choiceid=1]').prop('checked',true);

 


Forum|alt.badge.img+2
  • Author
  • Level 1 ●
  • 11 replies
  • April 11, 2024

Thanks Tom, I don’t suppose you would know how to hide the option as well? By the way I have noticed you have been the go to person on the forum when it comes to giving solutions. How did you know the library for Qualtrics in Javascript?


Forum|alt.badge.img+2
  • Author
  • Level 1 ●
  • 11 replies
  • April 11, 2024

Here is the code to prepopulate an option and hide it. The task was to read a code from a list and then fill a question and show the codes that had not been selected.

   var QB = "";
    QB = "${e://Field/eventCode}";

if (QB.length > 0)
    {
        jQuery('input[choiceid=' + QB + ']').prop('checked',true);
        jQuery('input[choiceid=' + QB + ']').closest("li").hide()
    }


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5938 replies
  • April 11, 2024

@LawrenceT,

Shorter, more efficient version:

jQuery('input[choiceid=' + QB + ']').prop('checked',true).closest("li").hide();

 


Forum|alt.badge.img+2
  • Author
  • Level 1 ●
  • 11 replies
  • April 11, 2024
TomG wrote:

@LawrenceT,

Shorter, more efficient version:

jQuery('input[choiceid=' + QB + ']').prop('checked',true).closest("li").hide();

 

Thanks again Tom. Would be good to know how to learn how to use Javascript in Qualtrics.


Leave a Reply