www.webdeveloper.com
Results 1 to 10 of 10

Thread: Carriage returns in javascript

  1. #1
    Join Date
    Jan 2003
    Posts
    628

    Carriage returns in javascript

    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.

  2. #2
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Yes, a carriage return is \n. Look at the code below.

    Code:
    <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.

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

  3. #3
    Join Date
    Jan 2003
    Posts
    628
    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?

  4. #4
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Post all you code.

  5. #5
    Join Date
    Jan 2003
    Posts
    628
    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.)

  6. #6
    Join Date
    Nov 2002
    Posts
    4,473
    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)
    Last edited by gil davis; 01-10-2003 at 09:17 AM.

  7. #7
    Join Date
    Jan 2003
    Posts
    628
    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.

  8. #8
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  9. #9
    Join Date
    Nov 2002
    Posts
    4,473
    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.

  10. #10
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Try replacing your ?? with \u0020\u0020 or \u0009 (Horizontal Tab - equivalent to three spaces.)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles