2

I have a video that I want to create as a variable so I can insert it into the HTML string. This is what I have right now.

Variable:

var vids = 'big_buck_bunny.mp4';

HTML string:

'<source type="video/mp4" src="videos/' + vids + '" />' 

When I refresh the browser it does not find the video

user2958098
  • 51
  • 2
  • 9

1 Answers1

0

You are missing a ", at the end of src="videos/, or at least, have mismatched quotes somewhere.

TylerH
  • 20,799
  • 66
  • 75
  • 101
  • 1
    @user2958098 I'm not very familiar with JavaScript, so I can't answer definitively. It just seems to be that you need another single *'* before `videos/` and remove the code after `vids`. Ex: `src="'videos/'` to specify the videos/ directory, then ` + vids '` to specify the variable. Combine those two and you would have `src="'videos/' + vids "` – TylerH Feb 27 '14 at 21:43
  • @user2958098 Check out [this SO question](http://stackoverflow.com/questions/4234533/how-do-i-concatenate-a-string-with-a-variable-javascript) and [this question, too](http://stackoverflow.com/questions/14554928/add-javascript-variable-to-javascript-src/) – TylerH Feb 27 '14 at 21:53
  • @user2958098 Can you post what ended up working for you? Just in case anyone else has the same/similar issue. Glad you were able to get it to work! – TylerH Feb 27 '14 at 22:46
  • 1
    I fully qualified the url var vids = 'http://localhost/ExpandableVideoUnit/videos/big_buck_bunny.mp4'; and then I put it above the hhtml string '' and it worked – user2958098 Feb 27 '14 at 22:49