Vignesh Kumar

Vignesh Kumar

  • NA
  • 1k
  • 415.9k

Split newline string using comma

Nov 20 2013 5:47 AM
Hi,
I need a javascript to split newline characters with commas. The below one, I am able to split white space and not the new line. Can anyone help me?
  <html>
  <head>
  <script>
  function convert() {
  var data = document.getElementById("get").value;
  var lines = data.split(' ');
  document.getElementById("display").value = lines.join(',');
  }
  </script>
  </head>
  <body>
  <div>
  Enter Code:
  </br>
  <textarea id="get"> </textarea>
  </br>
  <input type="button" value='Convert' onclick="convert()"/>
  </br>
  <textarea id="display"> </textarea>
  </div>
  </body>
  </html>



Answers (2)