One way I was thinking to do this is to disable the next button until the condition of moving the chair is met. The computer records the movement of the chairs with pixels using embedded data. If participants do not move the chairs the values for the embedded data fields "you x" and "you y" are left blank. Is there a way to write java code so that the next button will appear only if the chair is moved (if embedded data field is not blank)? I am not a programmer so am not sure what to do.
Here is a link to my task: https://qaz1.az1.qualtrics.com/jfe/form/SV_9Griq4aYcfbUBWl
Here is the embedded data code:
![](https://uploads-us-west-2.insided.com/qualtrics-us/attachment/ao_ap33yscn6m6g.jpg ""
Here is the code for the java script I currently have for this question:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
});
Qualtrics.SurveyEngine.addOnReady(function() {
//variables
var draggableClassName = ".chair"; // the class name of elements that should be draggable
var edField = "distance"; // this will be the name of the Embedded Data field with the distance.
var partnerx = "aPosition"; //this will get center x coordinate of Partner Chair
var partnery = "aPosition"; //this will get center y coordinate of Partner Chair
var youx = "bPosition"; //this will get center x coordinate of You Chair
var youy = "bPosition"; //this will get center y coordinate of You Chair
jQuery( function() {
jQuery( draggableClassName ).draggable({
stop: function() {
var distance = getDistanceBetweenElements(document.getElementById("Chair1"),
document.getElementById("Chair2"));
Qualtrics.SurveyEngine.setEmbeddedData('edField', distance);
}
});
});
var getPositionAtCenter = function (element) {
var data = element.getBoundingClientRect();
return {
x: data.left + data.width / 2,
y: data.top + data.height / 2
};
};
var getDistanceBetweenElements = function(a, b) {
var aPosition = getPositionAtCenter(a);
Qualtrics.SurveyEngine.setEmbeddedData('partnerx', aPosition.x);
Qualtrics.SurveyEngine.setEmbeddedData('partnery', aPosition.y);
var bPosition = getPositionAtCenter(b);
Qualtrics.SurveyEngine.setEmbeddedData('youx', bPosition.x);
Qualtrics.SurveyEngine.setEmbeddedData('youy', bPosition.y);
return Math.sqrt(
Math.pow(aPosition.x - bPosition.x, 2) +
Math.pow(aPosition.y - bPosition.y, 2)
);
};
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
});
Best answer by fleb
View original