I’m trying to make a progress bar that when it reaches 100% a sound will produce letting the user know that it’s done.
Here’s my JS:
const progress = document.querySelector(".progressStatus");
let finalValue = 100;
let max = 100;
function changeWidth()
{
// If it looks overly complicated I'm only at stage 1 I will use this formula more in the future
// but it works.
progress.style.width = `${(finalValue / max) * 100}%`;
progAudio();
}
function progAudio()
{
const progAudio = new Audio();
progAudio.src = "./audios/MONLU.mp3";
// I've tried singling out the audio
// didn't work
// progAudio.play();
setInterval(function () {
progAudio.play();
}, 1000);
}
and here’s my PHP:
echo
'
<button type="submit" class="" name="submit">
<a href="./phps/taskDone.php? doneid='.$taskId.'" onclick=progAudio(this wouldn't work); changeWidth(but this func does)">
Done
</a>
</button><br>';
I am also trying to pass data to my database that’s why it’s in PHP and the JS is just for design.
What confuses me is that the “changeWidth()”, the function that makes the progress bar load, works but the progAudio, the one that holds audio onclick, doesn’t. Both are JS but one doesn’t work.
I’ve tried just putting the progAudio() on the onclick but it doesn’t produce the audio.
I also tried putting them both in a single function
function progUp()
{
changeWidth();
progAudio();
}
and still didn’t work.
I researched and apparently php aren’t supposed to output audio but something tells me I’m just not making the PHP and the JS communicate properly.
Is there a way to do this? Ajax or through URL? Google wouldn’t tell me anything.
Thanks in advance!
2