Two IATs in the same questionnaire javascript, one overwriting the other | XM Community
Skip to main content

Hello, I have tried adding an IAT to my questionnaire using javascript following this websites instructions: https://minnojs.github.io/minnojs-blog/qualtrics-iat/

And it worked fine, here is the first JS code in qualtrics that reference my IAT in my questionnaire:

Qualtrics.SurveyEngine.addOnload(function () {
// hide question and next button
var container = this.getQuestionContainer();
container.querySelector('.Inner').style.display = 'none';
this.hideNextButton();

// load MinnoJS from the CDN (you probably don't need to change this)
var scriptTag = document.createElement('script');
scriptTag.src = 'https://cdn.jsdelivr.net/gh/minnojs/minno-quest@0.3/dist/pi-minno.js';
scriptTag.onload = onLoad;
scriptTag.onreadystatechange = onLoad;
container.appendChild(scriptTag);

// create the root element for Minno
var canvas = document.createElement('div');
container.appendChild(canvas);

// function to proceed to next question
var proceed = this.clickNextButton.bind(this);

// This function gets activated only after MinnoJS is loaded
function onLoad() {
// Run your study (just set the correct URL)
minnoJS(canvas, 'https://t2deb.github.io/Vurdering.github.io/IAT-endringer.js');

// MinnoJS doesn't know about Qualtrics, we pass a function to inject the results into the question
// For some reason `piGlobal` isn't available so we attach it to `minnoJS`
minnoJS.logger = function (value) {
var el = container.querySelector('textarea');
el.value = value;
}

// At the end of the study let MinnoJS proceed to the next question
// We need to wait a few miliseconds for Qualtrics to register the value that we entered
minnoJS.onEnd = function () { setTimeout(proceed, 100); }
}
});

The code im referencing can be found on my github account:

https://t2deb.github.io/Vurdering.github.io/IAT-endringer.js

As I said, this works completely fine as intended. The problem is when I add a second IAT later in my questionnaire (in a new block). Here is the JS for that in qualtrics:

Qualtrics.SurveyEngine.addOnload(function () {
// hide question and next button
var container = this.getQuestionContainer();
container.querySelector('.Inner').style.display = 'none';
this.hideNextButton();

// load MinnoJS from the CDN (you probably don't need to change this)
var scriptTag = document.createElement('script');
scriptTag.src = 'https://cdn.jsdelivr.net/gh/minnojs/minno-quest@0.3/dist/pi-minno.js';
scriptTag.onload = onLoad;
scriptTag.onreadystatechange = onLoad;
container.appendChild(scriptTag);

// create the root element for Minno
var canvas = document.createElement('div');
container.appendChild(canvas);

// function to proceed to next question
var proceed = this.clickNextButton.bind(this);

// This function gets activated only after MinnoJS is loaded
function onLoad() {
// Run your study (just set the correct URL)
minnoJS(canvas, 'https://t2deb.github.io/Vurdering.github.io/IAT-kjonn.js');

// MinnoJS doesn't know about Qualtrics, we pass a function to inject the results into the question
// For some reason `piGlobal` isn't available so we attach it to `minnoJS`
minnoJS.logger = function (value) {
var el = container.querySelector('textarea');
el.value = value;
}

// At the end of the study let MinnoJS proceed to the next question
// We need to wait a few miliseconds for Qualtrics to register the value that we entered
minnoJS.onEnd = function () { setTimeout(proceed, 100); }
}
});

Here is the code on my github page:

t2deb.github.io/Vurdering.github.io/IAT-kjonn.js

 

The problem is that the second IAT is also showning images when I go through the whole questionnaire (its supposed to just be words), the confusing part is when I preview the block for my second IAT everything works fine (images from the first IAT are not shown in the second IAT, and the words are correct). 

 

I am thinking it is some kind of overwriting issues using same names for variables or objects in my JS, but I don’t know.

 

Any help would be much appreciated!

Be the first to reply!

Leave a Reply