Ok, most of you know that you can output a new line in vbscript with vbCrLf. Is there anything like this in jscript?
Printable View
Ok, most of you know that you can output a new line in vbscript with vbCrLf. Is there anything like this in jscript?
check out \n
alert('blah\nmore blah on a new line');
Yes that would work for an alert, but i wanted to do something like:
Response.Write("<p>some text</p>\n");
Response.Write("<p>more text</p>");
and get the output of:
some text
more text
instead of
some textmore text
but the \n won't insert a new line in the output. I tried \r too, but that doesn't work either.
the \n will insert a new line in your output, but since browsers ignore carriage returns, you must output a <br> instead of a \n where you want the line break to occur
In other words, if you output a \n, your output will have a carriage return in it, but this is ignored by the browser. If you output a <br>, you will NOT have a carriage return in the output, but the browser will display a line break
I hope that makes sense....
Tom
I understand, but \n does not output a carriage return. When i look at the generated source, the \ns are all the little black box "undefined character"...all on one line.
Yeah, i have had this problem too. Why isin't there something like Response.Writeln?:confused:
There is something with the way Javascript outputs the new lines and notepad not recognizing it properly (you get the little box)
In windows 2000, notepad properly recognizes the new line, but in 9x or NT it appears as a little box. If you were to open that same source file in any other word processing program, the boxes are shown properly, so the CRLF does exist
I think i got it. You have to do \r\n. As in Response.write("Hello\r\nWorld"); gets you
Hello
World
.
How did you figure that one out?
Trial and error my friend.
But what exactly does \r do? Is it like \return?
Yeah, I think so, carriage return or something.
Sweet!
here's a list of some escape sequences I found in my Java book:
\b Backspace
\f Form Feed
\n New Line
\r Carriage Return
\t Tab
I wonder why \n doesn't do the same thing as \f\r? weird. Thanks Wynd, I need that \r for a project I'm working on