How to click on next-button with Javascript for multiple questions in the same block. | XM Community
Skip to main content

Hi there,

Some background on what I'm trying to accomplish in general: I'm trying to create an experiment with a task where the participant/user has to calculate the sum of 4 random 2-digit numbers (e.g. 40 + 33 + 20 + 99 = ...). In the same block, the user has a maximum of 25 sums to be solved with a time limit of 4 minutes. After these 4 minutes, the survey should move on to the next block automatically. I created some form validation with JavaScript to check if the user's input is correct (i.e. the calculation is correct). If it is correct then the user should be allowed to advance to the next question, if it is wrong the user receives an error message and is not allowed to proceed.
My problem: I've dissabled the Qualtrics-next button and created a custom-next button where, if the custom-next button is clicked, the Qualtrics-next button is clicked (following this discussion https://www.qualtrics.com/community/discussion/3273/getting-started-with-question-javascript). The problem now is that this only seems to be working for the first question, but not for any questions following after that.
var nextButton1 = document.querySelector(".NextButton")

if(Sum === userInput)
{
nextButton1.click()
}
else
{
ValidationError.innerHTML = "Incorrect answer"
}

This thus only works for question 1, but not for question 2-25. Does someone have any alternatives/suggestions?

Be the first to reply!

Leave a Reply