textarea and multiple lines and javascript!

Discussion in 'JavaScript' started by redhits, Dec 11, 2009.

  1. #1
    I need to add data to an textarea, via javascript
    the only problem is if i will use multiple lines in value.="" the script will fail to work !


    document.getElementById("textarea").value="domain1.com
    domain2.com
    domain3.com";
     
    redhits, Dec 11, 2009 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    An example for it!!!
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
      <title>Textarea</title>
    
    </head>
    
    <body>
    
    <textarea id="textarea" name="textarea" cols="20" rows="10"></textarea>
    
    </body>
       <script>
            document.getElementById("textarea").value="domain1.com\n\rdomain2.com\n\rdomain3.com";
       </script>
    </html>
    
    Code (markup):
     
    s_ruben, Dec 11, 2009 IP
  3. unigogo

    unigogo Peon

    Messages:
    286
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    document.getElementById("textarea").value = "domain1.com" + "\n"
    + "domain2.com" + "\n"
    + "domain3.com";
     
    unigogo, Dec 12, 2009 IP
  4. leeann.william

    leeann.william Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    In javascript you can concatenate you string by using + operator. the charcter with space also use the same concept. so try to do concatenation.
     
    leeann.william, Dec 17, 2009 IP