p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Classic ASP Databases (http://p2p.wrox.com/forumdisplay.php?f=62)
-   -   Checking for a Carriage return (http://p2p.wrox.com/showthread.php?t=22990)

darkhalf December 22nd, 2004 07:50 PM

Checking for a Carriage return
 
I have this textarea where people can type whatever... I store the information in an Access DB, but when I retrieve the information it just displays it in a straight line.

How can I check when a user presses the 'enter' key, to replace it by a <br> or something like that...

Any ideas...

thankx


Vadivel December 23rd, 2004 12:29 AM

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

Sumaira.noreen November 5th, 2007 06:15 AM

Yea this works on IE but not on Mozilla...:(can you please help me...how can it work on Mozilla and mac? [?]:(:(

Simply de Best...!!!


All times are GMT -4. The time now is 04:44 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.