Using a timer that spans pages and custom validation simultaneously | XM Community
Skip to main content

Hello everybody!
The goal for the participants of my survey is to solve as many exercises as possible in a limited amount of time.
Every exercise consist of a five-choice "Constant Sum"-Question, where the participants have to give their answers. These answers are checked via Custom Validation (Only one answer per choice is correct) and when the participant clicks the Next Button and all the answers are correct, the next exercise appears. If not, an error message is shown to the participants and they have to solve the same exercise again.
I implemented a timer that spans pages that I found here: https://medium.com/@mc_bloomfield/javascript-and-qualtrics-getting-started-34f113cbeaaa
The problem I have right now, is that if the timer is up, the participants should not be able to finish their current exercise and the questionblock should be finished right then and there.
Unfortunately, just using the "jQuery('#NextButton').click();" command in the JavaScript returnes the error-message, if the entries of the exercises are not correct. The error-message should appear as long the timer is running, but not after.
I tried to add another custom validation considering the timer, but this is quite hard: Unfortunately, it is not possible to use embedded data in custom validation, so I tried to implement another text field that changes its value when the timer is up, but I did not manage to get this right.
This is the code I considered for rewriting the value (and when it is set correctly, the page can be left without checking the other validations):
Qualtrics.SurveyEngine.addOnReady(function()
{
//run this command every second
var timer = window.setInterval(timeUpCheck, 1000);
function timeUpCheck() {
//TimeUp is an embedded variable and is changed from 0 to 1 when the timer runs out (programmed in header)
var timeUp = Qualtrics.SurveyEngine.getEmbeddedData('TimeUp');
jQuery("#"+this.questionId+" li input[type=text]").val(timeUp);
};
});

Qualtrics.SurveyEngine.addOnUnload(function()
{
clearInterval(timer);


});
Unfortunately, I've run out of ideas and google didn't help either...
Thanks in advance!

Be the first to reply!

Leave a Reply