Assign Textarea text to table cell without carriage returns - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Textarea

Description

Assign Textarea text to table cell without carriage returns

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script type="text/javascript">
   function test(){// w  w  w.  j  av  a2s .  c  o  m
      var x = document.getElementById('comments').value;
          x = x.replace(/\r?\n/g, '<br />');
      var y = '<table><tr><td>'+x+'</td></tr></table>';
      document.getElementById('tbl').innerHTML = y;
   }

      </script> 
   </head> 
   <body> 
      <div id="tbl"></div>  
   </body>
</html>

Related Tutorials