line break and document.write problem.

Discussion in 'JavaScript' started by mahmood, Jun 10, 2006.

  1. #1
    Sometimes I need to copy a long text and use document.write to write the text but the problem is that for every line I have to add a new document.write. for example this wouldn't work -"unteminated string literal" error -:
    
    document.write("this is line one.
    this is line 2.
    this is line 3.");
    PHP:
    so I have to code it like this:
    
    document.write("this is line one");
    document.write("this is line  two");
    document.write("this is line three");
    PHP:
    Somebody suggested the following but it has the same problem;
    
    var someText = "this is line one.
    this is line two.
    this is line three.";
    
    document.write(someText);
    PHP:
    Is there a command or something that I use and don't need to add that document.write for every single line?
     
    mahmood, Jun 10, 2006 IP
  2. the_pm

    the_pm Peon

    Messages:
    332
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This is so simple, you're going to kick yourself for not thinking of it ;)

    document.write("this is line one.<br>this is line two.<br>this is line three.");
    Code (markup):
     
    the_pm, Jun 10, 2006 IP
  3. mahmood

    mahmood Guest

    Messages:
    1,228
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for reply but this is not what I wanted. I bring an example, lets say you have this text on a webpage:
    This is line one.
    this is line two.
    ...
    This is line five hundred.
    PHP:
    Now you copythis 500 lines and want to use document.write to print it, you wouldn't want to go all the way an add a "<br>" to the end of each line and delete the carriage return.

    .

    .
     
    mahmood, Jun 10, 2006 IP
  4. brian394

    brian394 Well-Known Member

    Messages:
    226
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    108
    #4
    This won't work...

    
    document.write("this is line one.
    
    this is line 2.
    
    this is line 3."); 
    
    Code (markup):
    but this will...

    
    document.write("this is line one." +
    
    "this is line 2." +
    
    "this is line 3."); 
    
    Code (markup):
    Also, if you want to add the literal "newline" character just use \n in your string.
     
    brian394, Jun 12, 2006 IP