View Single Post
  #2 (permalink)  
Old December 23rd, 2004, 12:29 AM
Vadivel Vadivel is offline
Friend of Wrox
 
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

darkhalf,

1. This sample will work for windows encode and not in mac/unix encodes. If you want for that machines also do let me know.

2. This sample would convert the enter key at a stretch to break tags on click of a button. Instead if you want it to realtime, then use the Second Code snippet. (Note this sample will work for IE alone. For netscape you need use event.which in the function)

****FIRST Code snippet starts here ****
<html>
<head>
<script language="javascript">
function ConvertCarriageReturns(textarea, strReplace)
{
   textarea.value = escape(textarea.value)

   for(i=0;i<textarea.value.length;i++)
   {
      if(textarea.value.indexOf("%0D%0A") > -1 )
      {
         textarea.value = textarea.value.replace("%0D%0A",strReplace)
      }
   }
   textarea.value = unescape(textarea.value)
}
</script>
</head>
<body>
<form name="frmTest">
<textarea rows="7" cols="50" id="txtArea"></textarea>
<input type="button" onclick="ConvertCarriageReturns(this.frmTest.txtAr ea,'<br>')" value="Button">
</form>
</body>
</html>
****FIRST Code snippet ends here ****

RealTime Conversion:

****SECOND Code snippet starts here ****
<html>
<head>
<script language="javascript">
function RealTimeConvertion(e, textArea)
{
    var keyCode
     e = event
     keyCode = e.keyCode

   if(keyCode == 13)
   {
    textArea.value +="<br>"
    return true
   }
}
</script>
</head>
<body>
<form name="frmTest">
<textarea rows="7" cols="50" id="txtArea" onKeyPress="RealTimeConvertion(event,this)"></textarea></form>
</body>
</html>
****SECOND Code snippet ends here ****

Hope this helps!

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com