How to work the audio tag in HTML

How do change the audio selection that is played in the player with an input?
my code is at:
https://museum-self-guided-tour.glitch.me/

It works for me. I just hit on the hyperlinks and it ran.

If you mean the input, you can use elem.value and use it like the data-value attr

I’ve changed your code for /script.js

list.onclick = function(e) {
  e.preventDefault();

  var elm = e.target;
  var audio = document.getElementById('audio');

  var source = document.getElementById('audioSource');
  source.src = elm.getAttribute('data-value');

  audio.load(); //call this to just preload the audio without playing
  audio.play(); //call this to play the song right away
};
var form = document.querySelector('form'); 
form.onsubmit = function (e) {
e.preventDefault();
var val = form.querySelector('label').querySelector('input');
var audio = document.getElementById('audio');
var source = document.getElementById('audioSource');
source.src = "https://cdn.glitch.com/dd0c097b-d169-49bf-84cd-9dafe0cadacc%2F00"+val+".mp3?v=1611446205442";
audio.load();
audio.play();
};

Note that this will eventually break.

I do not want the list. I was hoping to take the numeric value entered in Station Number and play the .mp3 with that number. If a number is entered that does not correspond to a file number there should be a default value of 001 loaded.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.