Click here to Skip to main content
15,890,385 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to enter video name to textbox, press ENTER button then browser play video I have stored in my disk.
But I don't know how to get textbox value to HTML video src. Please help me. Thank you.

Here is my code:
JavaScript
function playVideo()
 {
        myVideo.play();
 }

HTML
<input name="txtText" type="text" id="txtText" size="20" maxlength="10"/>
 <video id="myVideo" width="640" height="360">
   <source src="love.mp4" type="video/mp4"> 
 </video>
 <input type="button" value="ENTER" width="20" height="20" onclick="playVideo();"/>

This src = "love.mp4" is fixed. How can I replace it with value I enter to textbox?
Posted

1 solution

Put ID to source tag
<video id="myVideo" width="640" height="360">
    <source id="VdoSrc" src="love.mp4" type="video/mp4"> 
</source></video>

You can get through javascript
var mp4Vid = document.getElementById('VdoSrc');
$(mp4Vid).attr('src', "/pathTo/love.mp4");

For more info check this Link
 
Share this answer
 
v4
Comments
Member 10390715 28-May-15 5:47am    
I don't know jQuery, so I have solution like this. Thanks for your help
function changeValue()
{
var newVal = document.getElementById('txtText').value;
//document.getElementById("myVideo").innerHTML = '';
document.getElementById("myVideo").innerHTML = '';
//document.write(newVal+".mp4");
myVideo.load();
myVideo.play();
}
Karthik Devaraj 28-May-15 7:34am    
Check this fiddle : http://jsfiddle.net/Karthik_Dev/dmreqh62/
Member 10390715 28-May-15 21:48pm    
thanks for your help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900