Using multiple choice question text to prefill text box of another question

MichelleCMichelleC East Lansing, MI Guru ✭✭

Using multiple choice question text to prefill text box of another question

I'm passing this along since I thought it might be helpful, but please know this is not my work! :) I am not a coder. This was developed by one of our super-heavy duty pro Qualtrics users here on campus and he's really good about keeping me in the loop on tricky things he solves.

This is to send multiple choice question text into the text box of another question. I'm just gonna C&P his text here:

It took me a day of work to figure this out, but I was able to better understand the object model Qualtrics uses for its questions so that I can get the text of a multiple choice question and send it to the text box of another question. I am worried I might loose it so I am pasting it below.

The really hard part was finding where information is kept in their object model and getting to it. I needed to pass something called “element” to a function in order to get to the parts. It was a little easier if I used this.questionclick() in the Qualtrics javascript API, but that is fired when someone clicks anywhere on the question, not just when it is changed.

Notes:
1) The questions are identified by the question IDs that Qualtrics gives them (ie QR~QID8). You can figure that out by using piped text in another question. The question ID comes out in the piped text (ie ${q://QID8/ChoiceGroup/SelectedChoices} ), you need to add the QR tilde in addition to the info you get from the piped text.
2) You can see the components of the element object when you pass element to the console log. I used chrome and then went to “more tools”, then “developer tools” (find them under the three dots in the upper right hand corner). Then I made sure that I could see console. The “element” object was then visible. The tough part initially was I could only see what I needed in the “this” object outside the function (I needed the items within the function I created) and could not figure out how to extract the part I needed (ask Catherine, she may be able to explain the “this” object, to be honest I am still working out how scoping of it works).

document.getElementById("QR~QID8").onchange = function(element){
       //console.log(element); // use console to look at element to find what you need in the qustion;
       var ele_var1=element.target.value.toString(); // gets selected option value  from question;
       var ele_var=element.currentTarget[ele_var1].Text; // gets text value of selected option;

       document.getElementById("QR~QID6").value=ele_var; //updates text question;
   }

Best Answer

  • AnthonyRAnthonyR Tucson Az Superuser ✭✭✭✭
    Accepted Answer

    This is great for same page questions, though if you have them on separate pages, you can use piped text directly as part of a "Default Choice".

Answers

  • MichelleCMichelleC East Lansing, MI Guru ✭✭

    @AnthonyR yeah, I wasn't sure what his use scenario for this was. He has some pretty complex survey designs that usually have to involve lots of code and API stuff, lol. :) Just thought I'd throw this out there in case anyone found use for it. I'm going to see if I can get him an invite to the Community because I think you two would have a lot to talk about.

Sign In to Comment