Page 1 of 1

Javascript Error.

Posted: Tue Oct 10, 2006 12:44 pm
by JellyFish
I get.
Error: unterminated string literal
document.write("
--------------------^
in this:

Code: Select all

document.write("
			<table style=\"border: 1px solid #CCCCCC;\">
				<tr>
					<td>
					<table width='500' height='400'>
						<tr height=\"0\">
							<td>
								<h2 style=\"font-family: Arial;\">Item Viewer</h2>
							</td>
						</tr>
						<tr>
							<td>
								<div align=\"center"\><img id=\"SelectedImg\" src=\"\" height=\"300\" width=\"475\" border=\"1\" style=\"border-right: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;\" /></div>
							</td>
						</tr>
						<tr height=\"30\">
							<td>
							
							</td>
						</tr>
						<tr>
							<td height=\"75\">
								<table>
									<tr>
										<td>
											<a href=\"\" onclick=\"return moveIS('left')\">
											<img src=\"images/ISLeft.png\" border=0 />
											</a>
										</td>
										<td width=\"100%\">
											<div id=\"IS\" style=\"border: 1px solid; border-right: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;\">
												<script language=\"javascript\">
												for (i in images)
												{
													if (i < 6)
													{
														numberOfISImages += 1;
														document.write(\"<a href='' onclick='return selectImage(document.ISimg\" + i + \".src)'><img ID='ISimg\" + i + \"' src='\" + images[i][0].src + \"' height='70' width='75' style='border: 1px solid black; border-left: 1px solid #CCCCCC; border-top: 1px solid #CCCCCC;' /></a>\");
													}
												}
												</script>
											</div>
										</td>
										<td>
											<a href=\"\" onclick=\"return moveIS('right')\">
											<img src=\"images/ISRight.png\" border=\"0\" />
											</a>
										</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
					</td>
				</tr>
			</table>
	");
of corse this is in script tags. Html I want to display works perfect when I just type it into the body. But no I want it to write through Javascript. Why is it that this error is comming up?

Posted: Tue Oct 10, 2006 1:19 pm
by feyd
Javascript doesn't do multi-line strings like that.

Code: Select all

<html>
	<head>
		<title>blah</title>
	</head>
	<body>
		<script type="text/javascript">
			var test = "hi\
			I'm a multiline\
			string";
			document.write(test);
		</script>
	</body>
</html>

<html>
	<head>
		<title>blah</title>
	</head>
	<body>
		<script type="text/javascript">
			var test = "hi\nI'm not a multiline\nstring";
			document.write(test);
		</script>
	</body>
</html>

Posted: Tue Oct 10, 2006 1:20 pm
by Luke
yup... it automatically inserts semi-colons if you forget them. Kind of annoying.

Posted: Tue Oct 10, 2006 1:38 pm
by feyd
I memory serves, it's a carry-over from C. Also, semicolons should always be used. If you are wondering why, run the code through a strict lint and you'll see lots of errors. :)