JavaScript for Customized Qualtrics Questions

Years ago, I wrote my online questionnaires from scratch with client-side JavaScript and Perl.  Nowadays, I’ve moved almost entirely to Qualtrics.  Creating and managing online questionnaires with Qualtrics is so easy that I’ve been spoiled by it.

However, I had a task I couldn’t accomplish with the typical question types, so I wrote a JavaScript solution for customizing Qualtrics questions.  I’m posting the solution here in case it’s useful to other people.  This mock-up questionnaire is an example of the sort of customized questions that could be created. The basic approach I describe below is straightforward, so you could adapt my JavaScript code to your favorite web programming language.

The basic approach

I put most of the questionnaire on Qualtrics for easy administration, and I only host the unusual questions that require customization on my off-Qualtrics server.  A respondent begins with part 1 of the questionnaire on Qualtrics, the respondent is then passed automatically to part 2 on my off-Qualtrics server, and the respondent is then transferred back to Qualtrics to complete the questionnaire in part 3.  This simplified questionnaire demonstrates the essence of the approach.

In part 1 (Qualtrics), under Edit Survey >> Survey Options >> Survey Termination >> Redirect to a URL, I use the following:

http://ederosia.byu.edu/off-qualtrics_questions/Off-Q
ualtrics_Questions_Part_2_the_essence_of_the_approach
.htm?Part_1_ResponseID=${e://Field/ResponseID}

This redirect transfers control to part 2 when part 1 is finished, and the redirect also writes a pseudo Get request in the URL to pass part 1’s Response ID to part 2.  Passing this variable is essential for the later task of linking the participant’s responses in part 1 with responses in part 3.

In part 2 (Off-Qualtrics), I use JavaScript (in files such as these) to read the Response ID from the URL, display customized questions, and collect responses.  At the conclusion of part 2, I use the following:

location.replace("https://byu.qualtrics.com/SE/?SID=S
V_cTFQ66RCUVDGg7z&Part_1_ResponseID=" + retrieve_from
_URL("Part_1_ResponseID") + "&quest=" + document.getE
lementById("quest").value);

This creates a URL that transfers control to part 3, and the URL writes a pseudo Get request that passes part 1’s Response ID and part 2’s responses.  For example, it could create a URL such as this:

https://byu.qualtrics.com/SE/?SID=SV_cTFQ66RCUVDGg7z
&Part_1_ResponseID=R_cBZfCDWBOqzgfPf&quest=I%20seek%
20the%20grail

In part 3 (Qualtrics), under Edit Survey >> Survey Flow >> Add a New Element Here >> Embedded Data (Value will be set from Panel or URL), I add the following fields :

  • Part_1_ResponseID
  • quest

This imports the data that is contained in the URL. Qualtrics automatically unescapes the strings.  By bringing in these fields as embedded data, the fields are available for download from Qualtrics as if they were normal questions in part 3.  That is, the responses to the customized questions in part 2 are stored in Qualtrics alongside the responses to the questions in part 3.

Before final data analysis, the datasets from part 1 and part 3 must be combined.  The part 1 ResponseID is available in both datasets, so it can be used as the unique key for merging the datasets.   An alternative would be to pass all the part 1 variables to part 2, and then pass all of them to part 3; this would put all the variables into part 3 and obviate the need to merge any datasets.  Another alternative would be to simply omit part 1 altogether and begin the online questionnaire with part 2.

Files available for download

The files on my server that yield the mock-up questionnaire and the very simplified questionnaire are available here.  These examples could be readily improved with CSS to closer mimic the Qualtrics visual style, and for the multiple-page mock-up questionnaire the parameters could be passed between pages with pseudo GET requests in the URL rather than with a browser cookie.

I hope these files are helpful to you in your adventures, but I cannot warranty them in any way, and any risk in using these files is your own.  Obviously, you should carefully pretest any web-based questionnaires before you field them.  You can freely use the files I have provided here; they are licensed under a Creative Commons License (Attribution 3.0).

– Eric DeRosia