Real Basic: document.writeln 
Author Message
 Real Basic: document.writeln

Why is it that when I write the following code, I do not get a line break?

document.writeln("x");
document.writeln("y");
document.writeln("z");

Instead of :
x
y
z

I get :
zyz

I thought the writeln inserted a carriage return?



Sat, 09 Oct 2004 06:17:17 GMT  
 Real Basic: document.writeln
I haven't come across this before but  try appending '\n' to your string to
create a newline.

eg.

document.writeln("x\n");
document.writeln("y\n");
document.writeln("z\n");

Chris Barber.


Why is it that when I write the following code, I do not get a line break?

document.writeln("x");
document.writeln("y");
document.writeln("z");

Instead of :
x
y
z

I get :
zyz

I thought the writeln inserted a carriage return?



Sat, 09 Oct 2004 06:46:24 GMT  
 Real Basic: document.writeln
Thanks Chris

That doesn't seem to work for me either.

I can get a line to break by including a <br> tag but I was curious why
writeln doesn't seem to work according to the documentation.  It might be
that it works in Netscape but not IE.

Thanks again
Dave


Quote:
> I haven't come across this before but  try appending '\n' to your string
to
> create a newline.

> eg.

> document.writeln("x\n");
> document.writeln("y\n");
> document.writeln("z\n");

> Chris Barber.



> Why is it that when I write the following code, I do not get a line break?

> document.writeln("x");
> document.writeln("y");
> document.writeln("z");

> Instead of :
> x
> y
> z

> I get :
> zyz

> I thought the writeln inserted a carriage return?



Sat, 09 Oct 2004 06:57:39 GMT  
 Real Basic: document.writeln
You're right - I'm an idiot - '\n' is for dialog boxes etc. Try it in an
alert.

HTML doesn't recognise those characters [carriage return and linefeed] - it
will only create a 'newline' for block HTML elements such as <BR><P></P> and
<DIV></DIV> etc.

writeln is just a method for outputting a series of text strings to a
device - in this case, the device (the browser) doesn't give two hoots about
arriage returns or linefeed characters (I believe that they are ASCII 10 and
13 respectively). The browser only cares about valid HTML.

For example the following HTML:

<P>
a
b
c
</P>

will actually show in the browser as:

a b c

even though the HTML patently has carriage returns and linefeeds in it.

However (as you have found)

<P>
a
b
<BR>
c
</P>

Will show as:

a b
c

Chris.


Thanks Chris

That doesn't seem to work for me either.

I can get a line to break by including a <br> tag but I was curious why
writeln doesn't seem to work according to the documentation.  It might be
that it works in Netscape but not IE.

Thanks again
Dave


Quote:
> I haven't come across this before but  try appending '\n' to your string
to
> create a newline.

> eg.

> document.writeln("x\n");
> document.writeln("y\n");
> document.writeln("z\n");

> Chris Barber.



> Why is it that when I write the following code, I do not get a line break?

> document.writeln("x");
> document.writeln("y");
> document.writeln("z");

> Instead of :
> x
> y
> z

> I get :
> zyz

> I thought the writeln inserted a carriage return?



Sat, 09 Oct 2004 07:35:08 GMT  
 Real Basic: document.writeln
"David said:

Quote:

>Why is it that when I write the following code, I do not get a line break?

>document.writeln("x");
>document.writeln("y");
>document.writeln("z");

>Instead of :
>x
>y
>z

>I get :
>zyz

>I thought the writeln inserted a carriage return?

It inserts a carriage return into the HTML source.

<html>
x
y
z
</html>

will display as:

x y z

because a carriage return in HTML is just whitespace.



Sat, 09 Oct 2004 07:34:04 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Real real basic question ...

2. document.writeln() question

3. unicode not support on document.writeln

4. document.writeln (without clear())

5. company/product name variables with document.writeln

6. Debugging IHTMLDocument2.writeln scripts

7. Problems with writeln

8. writeln problem

9. How to Writeln?

10. writeln across windows

11. Merge Two Single Page PS documents into one Single Page PS Document

12. printing a changed document.body without changing the existing document.body

 

 
Powered by phpBB® Forum Software