PDA

Click to See Complete Forum and Search --> : Question about Server-side JScript


Wynd
May 12th, 2001, 11:49 PM
Ok, most of you know that you can output a new line in vbscript with vbCrLf. Is there anything like this in jscript?

Crazy D
May 13th, 2001, 05:00 AM
check out \n
alert('blah\nmore blah on a new line');

Wynd
May 13th, 2001, 11:17 AM
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.

Clunietp
May 13th, 2001, 12:37 PM
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

Wynd
May 15th, 2001, 06:26 PM
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.

sail3005
May 15th, 2001, 06:30 PM
Yeah, i have had this problem too. Why isin't there something like Response.Writeln?:confused:

Clunietp
May 15th, 2001, 08:35 PM
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

Wynd
May 16th, 2001, 05:45 PM
I think i got it. You have to do \r\n. As in Response.write("Hello\r\nWorld"); gets you

Hello
World
.

sail3005
May 16th, 2001, 06:02 PM
How did you figure that one out?

Wynd
May 16th, 2001, 06:16 PM
Trial and error my friend.

sail3005
May 16th, 2001, 07:32 PM
But what exactly does \r do? Is it like \return?

Wynd
May 16th, 2001, 07:33 PM
Yeah, I think so, carriage return or something.

Clunietp
May 17th, 2001, 12:33 AM
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