Javascript: Textarea should replace break on enter

Use this code to  get break as user enters in the textarea. Hope this helps!

<html>
<head>
<title>Insert new lines dynamically</title>
<script type = "text/javascript">
 function fillTarg()
{
 var TARG = document.getElementById("newtext")
 var AREA = document.getElementById("textarea")
  TARG.innerHTML = AREA.value.replace(/\n/g,"<br>") // Replace break on user enters
 TARG.innerHTML = AREA.value.replace(/\s/g,"&nbsp;")  // Replace space on user enters
}
</script>
</head>
 

<body>
<textarea style="width:450px; height:150px;" id="textarea"  onKeyUp="fillTarg()">Click on the button below to add some lines!</textarea>
<br><br>
<span id="newtext"> </span>

</body>
</html>

Comments

Popular posts from this blog

Ghostscript Installation and Configuration in Windows 7

Joomla - Get user id