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

Prepopulate a multiple response question

  • Apr 9, 2024 4:15 AM UTC
  • 5 replies
  • 124 views

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 ●●●●●●●●
  • Answer
  • Apr 9, 2024 12:20 PM UTC
jQuery('input[choiceid=1]').prop('checked',true);

 


Forum|alt.badge.img+2
  • Author
  • Level 2 ●●
  • Apr 11, 2024 1:55 AM UTC

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 2 ●●
  • Apr 11, 2024 10:33 PM UTC

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 ●●●●●●●●
  • Apr 11, 2024 10:38 PM UTC

@LawrenceT,

Shorter, more efficient version:

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

 


Forum|alt.badge.img+2
  • Author
  • Level 2 ●●
  • Apr 11, 2024 10:43 PM UTC

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