Hi everyone!
Maybe someone can help me. I am trying to run a code on a page with 80 buttons that checks whether participants have selected all the buttons they are supposed to select. If they have, I want three things to happen:
- Participants get an alert telling them they did find all the buttons (works!)
- Percentage of corretly pressed buttons gets written in an embedded data field (does not work)
- Upon closing the alert, the Next-Button gets automatically pressed (does not work).
Any advice on how to make (2) and (3) happen would be greatly appreciated!
Here is the code I have so far:
Qualtrics.SurveyEngine.addOnload(function()
{
this.hideNextButton();
jQuery('.toggleable').on('click', function(){
jQuery(this).toggleClass('chosen unchosen');
var isChosen = jQuery(this).hasClass('chosen');
});
var correct = ;5, 6, 7, 13, 14, 33, 34, 41, 43, 49, 58, 59, 65, 79];
var ncorr = 0;
var wept_01 = 0;
jQuery('#check').on('click', function(){
var wrongSelected = false;
jQuery('.chosen').each(function () {
var chosenid = jQuery(this).attr('id');
if (chosenid) {
chosenid = +chosenid;
if (jQuery.inArray(chosenid,correct) > -1){
++ncorr;
}
else {
wrongSelected = true;
}
}
});
if (wrongSelected) {
alert ("There’s a mistake.");
return false;
}
else if (ncorr < correct.length) {
alert ("You missed some buttons.");
return false;
}
else {
var chosenPercentage = (ncorr / correct.length) * 100;
alert("Congrats, you found them all!");
return true;
Qualtrics.SurveyEngine.setEmbeddedData("ncor_prac1", chosenPercentage);
jQuery("#NextButton").click();
}
});
});