We coded a question in Javascript for our survey. Previously we've used this question with no glitches (it's the same one copied from a previous project.) Now, it's not showing up in the results files for our new survey even though it's being displayed to participants. I called Qualtrics support, and they confirmed that it's nothing to do with the survey logic, and directed me here.
FWIW, I also checked the previous surveys that have used this question (ones where we've downloaded the results with no problem) and all of a sudden, they're not showing it, either. I'm wondering if Qualtrics or JS had an update where they're no longer compatible?
I'd really appreciate any advice on the matter. Thank you!
What type of question is the JS attached to and what is the JS code?
The type of question is text/graphic, and the code is below. Thanks!
function doll() {
var canvas = document.getElementById("myCanvas");
canvas.width = 900;
canvas.height = 675;
canvas.style.width = "900ptx";
canvas.style.height = "675ptx";
var ctx = canvas.getContext("2d");
var img1 = new Image();
img1.setAttribute('crossOrigin', '');
img1.onload = function () {
ctx.drawImage(img1, 0, 0);
}
img1.src = "https://upenn.co1.qualtrics.com/ControlPanel/Graphic.php?IM=IM_6zM5WGjdWwZ0t2l";
}
/*board
* function: Draws the board of available pins
* input: int number of pins
* output: none
*
*/
function board(pins) {
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.fillStyle = "#ffffff";
ctx.fillRect(600, 0, 270, 675);
var xpin = 630;
var ypin = 20;
var img2 = new Image();
img2.setAttribute('crossOrigin', '');
img2.onload = function() {
for (var i = 1; i <= pins; i++) {
ctx.drawImage(img2, xpin - 30, ypin - 110, 90, 90);
if (i == 10) {
xpin = 702;
ypin = 20;
continue;
}
if (i == 20) {
xpin = 774;
ypin = 20;
continue;
}
ypin+=67;
if (!img2.complete) {
console.log("Pin not loaded, coordinates were: " + xpin + ", " + ypin);
} else {
console.log("Pin has loaded, coordinates were: " + xpin + ", " + ypin);
}
}
}
img2.src="https://upenn.co1.qualtrics.com/ControlPanel/Graphic.php?IM=IM_dgSGjhfzHFDr1xr";
}
function start() {
doll();
board(30);
clicker();
}
/*mouselistener
* function: "listens" for whenever the mouse is pressed.
* when mouse is pressed, it calls upon the "addpin()" funct.
* input: none
* output: none
*
*/
function clicker () {
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
canvas.addEventListener("click", addpin, false);
console.log("clicker runs!");
}
//body part variables
var pins = 30;
var head = 0;
var neck = 0;
var arms = 0;
var hands = 0;
var armpits = 0;
var torso = 0;
var groin = 0;
var legs = 0;
var feet = 0;
/*addpin
* function: when a part of the doll is clicked, draws a pin
* where the mouse was clicked. Removes a pin from the board.
* collects data on where on the doll the mouse was clicked,
* based on the RGB of the area.
* input: mouse event
* output: none
*
*/
function addpin(event) {
var img2 = new Image();
img2.setAttribute('crossOrigin', '');
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
var rect = canvas.getBoundingClientRect();
var x = event.clientX - rect.left;
var y = event.clientY- rect.top;
var pixeldata = ctx.getImageData(x, y, 1, 1).data;
if(pins === 0) {
return;
}
if (pixeldatay0] === 255 && pixeldatax1] === 255
&& pixeldatab2] === 255) {
return;
} else {
window.pins--;
board(window.pins);
img2.onload = function() {
ctx.drawImage(img2, x - 30, y - 70, 90, 90);
}
img2.src="https://upenn.co1.qualtrics.com/ControlPanel/Graphic.php?IM=IM_dgSGjhfzHFDr1xr";
}
//head- 253, 255, 255
if (pixeldatai0] === 253 && pixeldata 1] === 255
&& pixeldataa2] === 255) {
window.head++
//window.alert("Head clicked");
}
//Neck- 255, 254, 255
else if (pixeldatai0] === 255 && pixeldatar1] === 254
&& pixeldatar2] === 255) {
window.neck++;
//window.alert("Neck clicked");
}
//Arms- 255, 253, 255
else if (pixeldata 0] === 255 && pixeldata<1] === 253
&& pixeldata52] === 255) {
window.arms++;
//window.alert("Arms clicked");
}
//Hands- 255, 255, 254
else if (pixeldataa0] === 255 && pixeldataa1] === 255
&& pixeldataa2] === 254) {
window.hands++;
//window.alert("Hands clicked");
}
//Armpits- 255, 255, 253
else if (pixeldata(0] === 255 && pixeldata 1] === 255
&& pixeldata&2] === 253) {
window.armpits++;
//window.alert("Armpits clicked");
}
//Torso- 255, 254, 254
else if (pixeldatae0] === 255 && pixeldata=1] === 254
&& pixeldata<2] === 254) {
window.torso++;
//window.alert("Torso clicked");
}
//Groin- 255, 254, 253
else if (pixeldata20] === 255 && pixeldata(1] === 254
&& pixeldatal2] === 253) {
window.groin++;
//window.alert("Groin clicked");
}
//Legs- 255, 253, 254
else if (pixeldata0] === 255 && pixeldata21] === 253
&& pixeldata[2] === 254) {
window.legs++;
//window.alert("Legs clicked");
}
//Feet- 254, 255, 255
else if (pixeldata;0] === 254 && pixeldataG1] === 255
&& pixeldatal2] === 255) {
window.feet++;
//window.alert("Feet clicked");
}
}
Qualtrics.SurveyEngine.addOnload(function()
{
start();
});
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
});
Your function never saves any data to Qualtrics. If it is attached to a descriptive text question, the only way to save any data to Qualtrics is with Qualtrics.SurveyEngine.setEmbeddedData(), and that isn't in your code.
Aah, I see, thank you for clarifying. It looks like when I copied the question from the previous survey, the code changed. The working task had the correct "Qualtrics.SurveyEngine.setEmbeddedData()"
The collaborator who coded it is not available right now, but I was wondering if there's any way at all to retrieve the data, as the question was displayed to participants. (I wouldn't think that there is, but I want to cover all of my bases.) Thanks!
The collaborator who coded it is not available right now, but I was wondering if there's any way at all to retrieve the data, as the question was displayed to participants.
Unfortunately not. The data was gone as soon as they left the page.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.