Show Next button when audio is played + have a timer | XM Community
Skip to main content

hello,
I have a survey where I'm asking respondents to listen to a piece of audio and then there are follow-up questions. I want to measure how long they spend on the page - so that I have a sense if they skipped around in the audio - and I want to have the 'Next' button appear only when they reach the end of the audio clip.
I added a timer and I'm using this JS for the Next button display:
Qualtrics.SurveyEngine.addOnReady(function() {
  jQuery("#NextButton").hide();
  jQuery("#"+this.questionId+" audio").on("ended", function() { jQuery("#NextButton").show(); });
});
The script worked fine before I added the timer, but now it just displays the button immediately when the block loads.
Is there a way to both show the Next button when the audio reaches the end and have a timer in place?
Thank you very much!

That's probably because the timer question has an allow submit after option, which defaults to zero. Therefore, while you hide the next button, the timer question shows it instantly. Use this to add a delay. It will flash the next button for 500 ms and then hide it.

setTimeout(function () {jQuery("#NextButton").hide();},500) 


That did the trick! Thank you very much!


Do test it on a slower internet connection and on a few browsers.
You may need to increase the delay due to the difference in loading times.


Leave a Reply