Prepopulate a multiple response question | XM Community
Solved

Prepopulate a multiple response question

  • 9 April 2024
  • 5 replies
  • 40 views

Badge +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?

 

 

 

icon

Best answer by TomG 9 April 2024, 14:20

View original

5 replies

Userlevel 7
Badge +27
jQuery('input[choiceid=1]').prop('checked',true);

 

Badge +2

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?

Badge +2

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()
    }

Userlevel 7
Badge +27

@LawrenceT,

Shorter, more efficient version:

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

 

Badge +2

@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