In this tutorial, we will learn How to add line breaks to an HTML textarea


In this section, you will know how to add line breaks to an HTML Textarea. you can easily and simply add line breaks to an HTML textarea.

split(): is a predefined JavaScript function that splits a string into an array using a parameter.

join(): is a predefined JavaScript function that joins an array to convert it into a string using provided parameters.



Example :

<!DOCTYPE html> 
<html> 
<head> 
     <script type="text/javascript"> 
          function divide() { 
               var txt; 
               txt = document.getElementById('a').value; 
               var text = txt.split("."); 
               var str = text.join('.</br>'); 
               document.write(str); 
          } 
     </script> 
     <title></title> 
</head> 
<body> 
     <form> 
          ENTER TEXT: 
          <br> 
          <textarea rows="20"
                    cols="40"
                    name="txt"
                    id="a"> 
     </textarea> 
          <br> 
          <br> 
          <input type="submit"
               name="submit"
               value="submit"
               onclick="divide()" /> 
     </form> 
</body> 
</html> 

May this example help you.