Click to See Complete Forum and Search --> : Carriage returns in javascript


Webskater
01-10-2003, 07:11 AM
I need to write a long message in an alert box and want to put a carriage return at the end of each sentence. I know this is done using something like \n . Can anyone tell me exactly what it is and where I can get a list of characters for non-breaking spaces etc. I've tried ascii codes and iso-latin but these don't seem to work. Thanks for any help.

pyro
01-10-2003, 07:19 AM
Yes, a carriage return is \n. Look at the code below.

<script type="text/javascript">
alert("This\nis\na\ntest!");
</script>

Also, if you want non-breaking spaces in you alert, just add the spaces to you your code.

<script type="text/javascript">
alert("This is a test!");
</script>

Webskater
01-10-2003, 07:24 AM
Thanks for your reply. I am also trying to write to a table cell using innerText.
So my code says something like:
rows(i).cells(4).innerText = MyVariable + "??"
Where I put the two question marks I want to put two spaces - to indent the text away from the edge of the cell. Just putting two spaces here does not work. Any idea what will?

pyro
01-10-2003, 07:26 AM
Post all you code.

Webskater
01-10-2003, 07:52 AM
function recalc()
{
var row = event.srcElement.parentElement.parentElement;
var table = row.parentElement.parentElement;
var rows = table.rows.length;

//Update current row
var total = row.cells(2).firstChild.value * row.cells(3).firstChild.value
row.cells(4).innerText = "£" + total.toFixed(2) + "??";
}
The above function does some Maths and writes the answer to a cell. After the total is written I want to write two spaces - to indent the text from the side of the cell. In the code above I have put two question marks where I want the two spaces to appear. If I leave the question marks in they appear on screen. If I remove them and replace them with two spaces (" ") they don't appear on screen and the total is hitting the edge of the cell (which looks ugly.)

gil davis
01-10-2003, 08:05 AM
Can anyone tell me exactly what it is and where I can get a list of characters
They follow the conventions of C++.

\b = backspace
\f = form feed
\n = new line
\r = carriage return
\t = horizontal tab
\v = vertical tab
\nnn = whatever character nnn is, base8 (\101 = A)

Webskater
01-10-2003, 09:38 AM
Thanks for your replies. In the last reply it was stated the convention follows C++ with a slash followed by the base8 character reference. Any idea where I can find a list of base8 character codes.

Charles
01-10-2003, 09:47 AM
See http://devedge.netscape.com/library/manuals/2000/javascript/1.5/guide/ident.html#1008368.

gil davis
01-10-2003, 09:55 AM
Originally posted by Webskater
Any idea where I can find a list of base8 character codes.
It is also called "octal". It's still the Unicode character set, but the decimal number needs to be converted to octal or base 8.

pyro
01-10-2003, 10:00 AM
Try replacing your ?? with \u0020\u0020 or \u0009 (Horizontal Tab - equivalent to three spaces.)