0

I am designing a survey in Qualtrics which has around 200 items. Each item is presented one question per page. I want questions to auto-advance when they click a response.

I can see how you can do this one question at a time using the code here:

Qualtrics.SurveyEngine.addOnload(function()
{
    var that = this;
    this.questionclick = function(event,element){
        if (element.type == 'radio')  {
            that.clickNextButton();
        }
    }
});

and the method describe in the help files here. Basically, the idea is that you click on the javascript button for a question and paste in the code.

However, this process would be tedious to repeat 200 times, and if I wanted to tweak the javascript, I would again have to repeat the process 200 times.

Is there a way of applying java script to a set of questions in Qualtrics?

Jeromy Anglim
  • 33,939
  • 30
  • 115
  • 173

3 Answers3

1

A much easier way would be to put the JavaScript in the header or footer (Look & Feel/Advanced), then it would apply to every page in the survey.

<script type="text/javascript">
Qualtrics.SurveyEngine.addOnload(function() {
     // script logic goes here
});
</script>
T. Gibbons
  • 4,919
  • 2
  • 15
  • 32
  • Thanks. Your approach would be great. However, I tried that approach, and it didn't work. I.e., I tried pasting the code as shown in my question (i.e., `var that = this`, etc) into the header. Do you think it needs to be adapted to work in the header? I.e., to work as a general script across questions? – Jeromy Anglim Jun 12 '17 at 23:37
  • Using some other scripts I can get header to work but only for the first question as per this problem: https://stackoverflow.com/questions/31754742/why-does-my-qualtrics-js-in-header-only-seem-to-work-for-the-first-page – Jeromy Anglim Jun 13 '17 at 00:06
  • You'll need to adjust your script because 'this' is no longer the question (i.e. this.questionId). You'll have to have the script find the question. On you other issue, under Look&Feel, set page transition to 'None'. Also, best practice is to put JavaScript in the footer. – T. Gibbons Jun 13 '17 at 13:23
0

One option is to export the survey, edit the export file, and reimport the survey into Qualtrics. This method is not well documented in Qualtrics support, but it does work. This help file explains how to export and import a Qualtrics survey as QSF file (i.e., Qualtrics Survey Formatting file).

Thus, the main challenge is to work out how to edit the QSF in order to add the relevant java script 200 times.

The QSF file is in JSON format. Prior to this, I'd heard of, but never had to use JSON format. Perhaps this is typical of Qualtrics users.

By default the QSF file is in a serial form (i.e., it's on one line). I found this online editor helpful for formatting and parsing the hierarchical structure of QSF files. json qsf files qualtrics

In general, the structure of QSF files starts with a SurveyEntry that has general survey specifications. It then has a bunch of SurveyElements. The first six elements in my example related to general features of the survey. In particular, the first elements represented the blocks and set out the order of questions in the block. After the first six were the questions. Each question include a range of ID type variables followed by the Payload. The Payload includes the core attribute-values pairs that control features of the question.

In particular, the javascript for a question is maintained in the QuestionJS variable. I don't think the order of the attributes in the Payload matters, but I'm not really sure.

So the task is simply to add some code like this inside the Payload attribute of each question.

"QuestionJS":"Qualtrics.SurveyEngine.addOnload(function()\n{\n    var that = this;\n    this.questionclick = function(event,element){\n        if (element.type == 'radio')  {\n            that.clickNextButton();\n        }\n    }\n\n\n});",

Presumably, there are better ways of editing json scripts that make better use of the data structure, but it should be possible to do a simple find and replace. For example, if all your questions are of type multiple choice, you could do something like

Find:

 "QuestionType":"MC",

Replace

 "QuestionType":"MC","QuestionJS":"Qualtrics.SurveyEngine.addOnload(function()\n{\n    var that = this;\n    this.questionclick = function(event,element){\n        if (element.type == 'radio')  {\n            that.clickNextButton();\n        }\n    }\n\n\n});",  

This idea could be extended to other occasions where you want to add a particular attribute to a set of questions.

Jeromy Anglim
  • 33,939
  • 30
  • 115
  • 173
0

One approach is to use "Loop & Merge".

You create a block with a single template item that mirrors the format that you want for your question. Include the java script that you want in the question and any other features that you want.

Then turn on loop and merge and paste the text for each of the questions into Field 1. E.g., here's what it looks like.

sample items loop and merge

You can then pipe in this text into the template question:

template question qualtrics

There is more information about loop & merge on the qualtrics suport site

And if you need to randomise and record order, there are details here.

Jeromy Anglim
  • 33,939
  • 30
  • 115
  • 173