I have a select with 2 options and the audio should change according to the selected option. The select is showing as it should with both options available but the audio is not showing so i think the issue lies in the following line:
audioFiles.options[audioFiles.selectedIndex].id == "English"
<div>
<i>Audio:</i>
<select id="audioFiles" onchange="toggle()">
<option id="English" value="audio/english.mp3">
English
</option>
<option id="German" value="audio/german.mp3">
Deutch
</option>
</select>
<audio controls id="audioPlayer">
<source id="mp3" type="audio/mpeg">
<source id="ogg" type="audio/ogg">
<source id="wav" type="audio/wav">
<embed id="embedded" height="50" width="100">
</audio>
</div>
function toggle()
{
var audioFiles = document.getElementById("audioFiles");
var mp3 = document.getElementById("mp3");
var ogg = document.getElementById("ogg");
var wav = document.getElementById("wav");
var embedded = document.getElementById("embedded");
if (audioFiles.options[audioFiles.selectedIndex].id == "English") {
var audioPath = document.getElementById("English");
mp3.src = audioPath.value;
ogg.src = audioPath.value;
wav.src = audioPath.value;
embedded.src = audioPath.value;
}
else if(audioFiles.options[audioFiles.selectedIndex].id == "German")
{
var audioPath = document.getElementById("German");
mp3.src = audioPath.value;
ogg.src = audioPath.value;
wav.src = audioPath.value;
embedded.src = audioPath.value;
}
}
Are any of you able to see what i am doing wrong? I am not using jQuery and the paths to the files are as they should be.