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";
}
};