I'm trying to create a DTMF keypad emulator using only HTML, CSS, and JavaScript,
I'm having a small problem with sound. When an image is clicked, that runs the offHook() function which starts playing dial tone. However, I want that dial tone to stop as soon as the first number is clicked (or pressed once I had a keyboard listener). For each number function i.e. dial1(), dial2(), etc. which is tied up to the individual buttons that are clicked, I run the numberDial() function, which is supposed to stop the dial tone audio. However, it refuses to stop.
I have tried:
-dialTone.pause();
-dialTone.stop();
-dialTone.src = "";
Regardless, the dial tone continues. How can I get it to stop when numberDial() is run? This function is run every time a number is pressed (I'll add other stuff later) so it will only be stopping the audio the first number, but it shouldn't do any harm the other times either.
My understanding is that the function numberDial() should recognize the variable dialTone - so why is dialTone refusing to pause?
function offHook() {
document.getElementById("WE2500").style.display = "none";
document.getElementById("dialPad").style.display = "block";
var dialTone = new Audio('dialTone.m4a');
dialTone.play();
}
var number = "";
function numberDial() {
dialTone.src = "";
}
function dial1() {
numberDial();
number = number + "1";
var tone1 = new Audio('DTMF-1.wav');
tone1.play();
}