I am working on a streaming website and I don't know how to call a Javascript variable in the HTML src attribute for displaying a video. The only way that I know how to solve this is by creating multiple pages and hard coding the video names themselves into it. All of the files are named EP1.mp4, EP2.mp4, EP3.mp4, etc. I need to find out how to make the number [EP->1<-.mp4] into a variable and call it into the src attribute so it knows where to look. I am new to HTML and Javascript.
I have tried putting the javascript variable in single quotes, +'s, and quotes but to no avail.
page1.html
<button onclick="ep1()">Episode1</button>
<button onclick="ep2()">Episode2</button>
<script>
function ep1() {
var Epinum = "1";
var Anime = "Toradora!"
localStorage.setItem("Epinum",Epinum);
localStorage.setItem("Anime",Anime);
window.location = 'page2.html';
}
function ep2() {
var Epinum = "2";
var Anime = "Toradora!"
localStorage.setItem("Epinum",Epinum);
localStorage.setItem("Anime",Anime);
window.location = 'page2.html';
}
</script>
page2.html
<video src="OGAnime/+'Anime'/EP+'Epinum'.mp4" width="320" height="240" controls>
Video not supported
</video>
I would like the command to be as shown
<video src="OGAnime/[Anime var goes here]/EP[Epinum var goes here].mp4" width="320" height="240" controls>
Video not supported
</video>
document.querySelector('#idvideotag').src = `begin${var}end`