#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    27
    Rep Power
    0

    Adding values to a textarea but seperating them line by line as opposed to one line


    Hello,

    I need your help,

    How can the code be modified below so as to allow the newly added values to appear on separate lines as opposed to just on the same line when the add button is clicked?

    Expected Result:
    ----------------------
    Red
    Blue
    Green
    Yellow

    Current Result:
    ----------------------
    RedBlueGreenYellow

    Code:
    <!DOCTYPE html>
    
    <html>
    
    <head>
    
    <script type="text/javascript">
    
    function add() {
    document.getElementById('list').value += document.getElementById('input').value
    
    }
    
    </script>
    
    </head>
    
    <body>
    <input type="text" style="width: 154px;" id="input">
    <input onclick="add()" type="button" style="width: 20px; height: 22px;" value="+" id="add"><br>
    <textarea style="height: 75px;" id="list"></textarea>
    </body>
    
    </html>
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7170
    "\r\n" is a carriage return followed by a newline; try adding that to the end of your textarea after you add a value.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo