Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

250
Views
Cap number of times an audio can be played: audio button disappears but one can still play the audio

I'm preparing a survey where I ask people to listen to a number of audio files once only. To do that, I've used a javascript that hides the audio button after the audio has been played X number of times. The problem is that, although the button disappears when it should, one can still play the audio file by clicking on the empty space where the button used to be. Is there a way to avoid this - for instance by disabling controls or mouse click after an audio has been played?

Below is a part of javascript that I have at the moment, courtesy of a kind Qualtrics user. Any idea as to how I can amend it? I'm a coding newbie so any help is hugely appreciated!

Many thanks!

Chiara

// CREATE playAudio() FUNCTION
function playAudio() {
playcount++; //increase playcount number by 
1
console.log(playcount); 
var button = 
document.getElementById("audiobutton"); 
//grab button id
button.style.visibility = "hidden"; //hide 
the button so that it can't be played 
anymore
audio.play(); //play the audio one last 
time 
//update play_count embedded data to 
current 
playcount number 

 Qualtrics.SurveyEngine.setEmbeddedData("play_co 
unt", playcount); 
     };



audio.onended = function() {
if (playcount < 1){
    var button = 
document.getElementById("audiobutton"); 
//grab button id
    button.style.visibility = "visible"; 
//show button again
} else {
            button.style.display = "none"; 
 }
 }; 
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!