faqts : Computers : Programming : Languages : JavaScript : Language Core : Strings

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

68 of 123 people (55%) answered Yes
Recently 4 of 10 people (40%) answered Yes

Entry

How can you put in a newline character within a string constant without getting the "Unterminated string constant" Javascript error

Jan 12th, 2001 06:32
Juergen Thelen, Rawlie Poulson,


For javascript driven html outpout just use the <br> tag
  var s = "line1<br>line2<br>line3";
  document.write(s);
This should work in any browser (<br> tag introduced with HTML 2.0).
Inside alerts you can use \n to force a new line
  var s = "line1\nline2\nline3";
  alert(s);
This should work in any browser on windows/mac os platforms at least. 
Never tested it on other platforms...
Hope this helps.
Juergen