This is the initial text in Text Area
After clicking on format button.
- <html>
-
- <head>
- <script type="text/javascript">
- function formattext(id)
- {
- var input = document.getElementById(id).value;
- console.log("The First Time user enters data : " + input)
- input = input.replace(/ +/g, " ");
- console.log("When spaces are removed : " + input)
- input = input.replace(new RegExp('\r?\n', 'g'), '<br />');
- console.log("When new line is removed : " + input);
- input = input.replace(/<br\s*\/?>/g, '');
- console.log("When br is removed : " + input)
- document.getElementById(id).value = input;
- }
- </script>
- </head>
-
- <body>
- <textarea id="txtareaProjectDes" rows="4" cols="50">
- </textarea>
- <button onclick="formattext('txtareaProjectDes')">Format Text</button>
- </body>
-
- </html>