0

I want to pass javascript variable as src to html5 video so that the video changes dynamically based on the js variable value. However I am not able to achieve it

<script type="text/javascript">
        var path = "/api/Videos/mp4/";
        var filename = '@ViewBag.filename';
        var fullPath = path.concat(filename);
        document.getElementById('fullPath1').src = fullPath.toString();        
</script>
<p><script type="text/javascript">document.write(fullPath)</script></p>
 <video width="480" height="320" controls="controls" autoplay="autoplay">
     <source src="fullPath1" type="video/mp4">
 </video>

Please help me to get this working. Thanks!

d12
  • 1
  • 3
  • 1
    you do not have any element with an id attribute set to `fullPath1` – Patrick Evans Oct 30 '15 at 21:01
  • Possible duplicate of [Can I use javascript to dynamically change a video's source?](http://stackoverflow.com/questions/3732562/can-i-use-javascript-to-dynamically-change-a-videos-source) – Hunter Turner Jan 14 '16 at 18:53

1 Answers1

0

you are looking for an element by id

document.getElementById('fullPath1').src = fullPath.toString();

but you haven't yet define any id:

<source src="fullPath1" type="video/mp4">
Ahmad Mousavi
  • 533
  • 1
  • 6
  • 17