View Full Version : Adding a carriage return character to a string

Oct 21st, 2009, 11:52 PM
Hi all

I am fairly used to programming, but not javascript, and I'm struggling a bit here...

I am building a string inside a variable prior to printing it on screen as follows :

myclock += hours+':'+minutes;
where "hours" and "minutes" are variables initialised elsewhere.

How can I add a carriage return or new line character to the end of this line, so that anything else cocatenated to this variable is displayed on the next line.

Thanks and have a nice evening.


rnd me
Oct 22nd, 2009, 12:57 AM
myclock += hours+':'+minutes+'\n';

Oct 22nd, 2009, 01:27 AM
Not necessarily just a newline character (\n). If displaying though a browser (it is javascript, after all), an HTML line break is needed: <br />

The newline character will make a newline in the source code.

Oct 22nd, 2009, 08:05 AM
That's great. Thanks for the help guys:thumbsup:.


Oct 22nd, 2009, 10:19 AM
\r is carriage return

rnd me
Oct 22nd, 2009, 11:54 AM
\r is carriage return

it doesn't look like one to me, smarty pants!