Note that there are some explanatory texts on larger screens.

plurals
  1. POVideo selection using <select> tag does not work
    primarykey
    data
    text
    <p>I am implementing a video selection functionality to my video play so that people can choose which video they would like to watch. My current code goes like this:</p> <p>html:</p> <pre><code>&lt;video id="media" width="600" height="400" preload="none"&gt; &lt;source id="myvideos" src="files/Best of 60s.m4v"&gt; &lt;/source&gt; &lt;/video&gt; &lt;select id="videos"&gt; &lt;option value="PleaseSelect" selected="selected"&gt;Please Select...&lt;/option&gt; &lt;option value="files/Best of 60s.m4v"&gt;Best of 60s&lt;/option&gt; &lt;option value="files/Black and White Gems.m4v"&gt;Black and White Gems&lt;/option&gt; &lt;/select&gt; </code></pre> <p>Javascript:</p> <pre><code>var selectmenu, mmedia; selectmenu=document.getElementById('videos'); mmedia = document.getElementById('media'); selectmenu.addEventListener('onchange', loadvid); function loadvid(){ selectmenu.onchange=function(){ var chosenoption=this.options[this.selectedIndex]; if (chosenoption.value != "PleaseSelect"){ mmedia.src = chosenoption.value; } mmedia.load(); } } </code></pre> <p>When I run this code no "link" gets created between what I choose in the select menu to what plays except for what I have stated in the src element.</p> <p>I implemented this with the following mindset:</p> <p>To have an onchange event attached to the select element so the function loadvid() only fires off when something changes in the menu. </p> <p>The loadvid function than manages the choice of video by defining the value of the selected index and passing it to mmedia; which is a video element and has the src property.</p> <p>Once the selection is made the video then should load (mmedia.load()). </p> <p>I have obviously gone wrong somewhere and would appreciate any guidance you can provide.</p> <p>Many thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload