Tanasa Paul Tanasa Paul - 4 months ago 8
Javascript Question

How can I load a sound by input value using javascript?

In the first, I use Firefox. I have code for a HTML spectrum, but I can't load sound from a textbox using input's id and javascript.

This is input:

<input type="text" id="song" value="first.mp3"></input>


And this is a part of javascript's code, the other part is for making spectrum:

var song = document.getElementById('song').value;
loadSound(song.value);


If I use directly values without input, for example
loadSound("first.mp3");
, code work, sound is loaded and it starts to play.

This is my full code, but doesn't run on jsfiddle.net because there is no sound for import: https://jsfiddle.net/77js54b4/.

But how can I make a load sound from input textbox?

Answer

It looks like you're using value twice in your example...

var song = document.getElementById('song').value; loadSound(song.value);

If document.getElementById('song').value = "song.mp3", then loadSound(song); should work according to what you mentioned.

Comments