Free2Code
The majority of forums are now only available as archives, which means posting/editing is disabled.

The Anything and Everything forum is still open.
 
Time: 2013-05-21, 04:00pm
No Subject
Subject: No Subject  ·  Posted: 2003-10-23, 09:38am
Rank: ? (5)
Member #: 10866
I'm working on some code for an administration page for an e-mail my company sends out. The people who are goint to be updating this don't know HTML, but in order to output the text with the right formating the text has to have some html code. Is there anyway to make a text box automatically insert a < br > tag when someone pushes the enter key on the keyboard? Or does anyone know of any other ways to do this? If anyone can help that would be great.

Thanks
Andy

 
  Reply to this ·  Post link ·  Top
Subject: Re: No Subject  ·  Posted: 2003-10-23, 10:06am
Rank: ? (4827)
Member #: 3416
yes there is a way to do this. well actually it changes to <br> when you click the submit button on the form. just put an onclick in there and point it to the javascript that i will post once i find it . . .

my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
 
  Reply to this ·  Post link ·  Top
Subject: Re: No Subject  ·  Posted: 2003-10-23, 10:46am
Rank: ? (4827)
Member #: 3416
crap sorry i don't seem to have it anymore. basically you just look for "\r\n", then "\r", then "\n", each time replacing with "<br>"
you'd probably be doing this with the value of a textbox.

my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
 
  Reply to this ·  Post link ·  Top
Subject: Re: No Subject  ·  Posted: 2003-10-23, 10:52am
Rank: ? (4827)
Member #: 3416
hey, i found it after all:

Code:
  1. function replaceChar(base, rid, add) {
  2.   for (var p = base.indexOf(rid); p > -1; p = base.indexOf(rid))
  3.     base = base.substring(0, p) + add + base.substring(p + rid.length);
  4.   return base;
  5. }

put this for your onclick on the submit button: javascript:document.formname.textareaname.value = replaceChar(document.formname.textareaname.value, '\n', '<br />');

this only worries about the \n though, but that doesn't matter.

my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
 
  Reply to this ·  Post link ·  Top
Subject: Thank you  ·  Posted: 2003-10-27, 09:29am
Rank: ? (5)
Member #: 10866
Thanks thats exactly what I was looking for. Sorry that I didn't reply earlier, but I've had a busy couple days here. Once again thanks a lot.

Andy

 
  Reply to this ·  Post link ·  Top
Subject: Re: No Subject  ·  Posted: 2003-10-27, 10:52am
Rank: ? (4827)
Member #: 3416
no problem--glad it worked for you!

my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
 
  Reply to this ·  Post link ·  Top
Subject: Am I doing this right?  ·  Posted: 2003-10-28, 09:00am
Rank: ? (5)
Member #: 10866
OK I'm probably just being stupid (especially since I really don't do much with javascript), but am I putting this in right, because I can't seem to get it to work.

Code:
  1. <html>
  2. <head>
  3. <title>Untitled Document</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. <script language="JavaScript">
  6. function replaceChar(base, rid, add) {
  7.   for (var p = base.indexOf(rid); p > -1; p = base.indexOf(rid))
  8.     base = base.substring(0, p) + add + base.substring(p + rid.length);
  9.   return base;
  10. }
  11. </script>
  12. </head>
  13. <body>
  14. <form method="post" name="form1" action="<cfoutput>#CurrentPage#</cfoutput>">
  15.   <table align="center">
  16.     <tr valign="baseline">
  17.       <td nowrap align="right">Title:</td>
  18.       <td><input type="text" name="title" value="" size="32">
  19.       </td>
  20.     </tr>
  21.     <tr valign="baseline">
  22.       <td nowrap align="right" valign="top">Body:</td>
  23.       <td>
  24.         <textarea name="body" cols="50" rows="5"></textarea>
  25.       </td>
  26.     </tr>
  27.     <tr valign="baseline">
  28.       <td nowrap align="right">Date:</td>
  29.       <td><input type="text" name="date" value="" size="32">
  30.       </td>
  31.     </tr>
  32.     <tr valign="baseline">
  33.       <td nowrap align="right">IssueNo:</td>
  34.       <td><input type="text" name="IssueNo" value="" size="32">
  35.       </td>
  36.     </tr>
  37.     <tr valign="baseline">
  38.       <td nowrap align="right">SortNo:</td>
  39.       <td><input type="text" name="SortNo" value="" size="32">
  40.       </td>
  41.     </tr>
  42.     <tr valign="baseline">
  43.       <td nowrap align="right">&nbsp;</td>
  44.       <td><input type="submit" value="Insert Record" onclick="javascript:document.formname.textareaname.value = replaceChar(document.formname.textareaname.value, '\n', '
  45. ');">
  46.       </td>
  47.     </tr>
  48.   </table>
  49.   <input type="hidden" name="MM_InsertRecord" value="form1">
  50. </form>
  51. <p>&nbsp;</p>
  52. </body>
  53. </html>


Thanks for the help

 
  Reply to this ·  Post link ·  Top
Subject: Re: No Subject  ·  Posted: 2003-10-28, 09:52am
Rank: ? (4827)
Member #: 3416
you have to actually replace formname and textareaname with the names you specified in your html. for this example, formname -> form1 and textareaname -> body.
should have pointed that out--sorry

my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
 
  Reply to this ·  Post link ·  Top
Subject: Thankyou  ·  Posted: 2003-10-28, 10:13am
Rank: ? (5)
Member #: 10866
No you shouldn't have had to point that out, I should have noticed that. I think ColdFusion has burnt my brain. Oh well. Once again Thanks.

Andy

 
  Reply to this ·  Post link ·  Top

Pages: 1

Please login or register to post a reply.

Penguino AVR

Want to learn about robotics or microcontrollers?
Check out the Penguino AVR from our friends at
Icy Labs