-1

Possible Duplicate:
How do I break a string across more than one line of code in JavaScript?

I am getting an unterminated string literal error. Please see my code

<script type="text/javascript">
function embedVideo(url){
alert(video);
var video= '
<OBJECT ID="player" width="800" height="450" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" STANDBY="Loading Windows Media Player components..." TYPE="application/x-oleobject">
<PARAM NAME="FileName" VALUE="">
<PARAM name="autostart" VALUE="false">
<PARAM name="ShowControls" VALUE="true">
<param name="ShowStatusBar" value="true">
<PARAM name="ShowDisplay" VALUE="false">
<param name="uiMode" value="full" />
<PARAM NAME="SendPlayStateChangeEvents" VALUE="True" />
<EMBED TYPE="application/x-mplayer2" width="800" height="450" SRC="" NAME="MediaPlayer"
ShowControls="1" displaysize="4" ShowStatusBar="1" ShowDisplay="0" autostart="0"> </EMBED></OBJECT>
';
alert(video);
jQuery("#videoScreen").html(video);
return true;
}
</script>

Please help...

Community
  • 1
  • 1
DeDav
  • 353
  • 2
  • 4
  • 11

3 Answers3

12

Javascript doesn't support multi-line strings, you'll need to either:

  • make that tag one big line, or
  • use a trailing backslash on each line to indicate "continuation", or
  • use multiple strings joined together.
Alnitak
  • 334,560
  • 70
  • 407
  • 495
2

I have copied and pasted the code into my machine. And I found the error.

On line 4,

var video= '
<OBJECT ID="player" width="800" height="450" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" STANDBY="Loading Windows Media Player components..." TYPE="application/x-oleobject">

This is causing the error. You have put a line break on line 4 after the equal to = sign. Javascript considers every line break as new statement. Please remove unnecessary line breaks and it should work.

Thanks.

Pupil
  • 23,834
  • 6
  • 44
  • 66
0

You can't assign multiline values to a variable in js, so you have to write it this way:

var video = '<OBJECT ...>';
video += '...';

But... the way you're creating an object element is not correct - you'd better use document.createElement for more clear code.

k102
  • 7,861
  • 7
  • 49
  • 69