Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Remove hard carriage returns

Posted on 2004-04-06
Last Modified: 2010-04-06
I have a text area box where users can describe a problem their having, but the problem is when the data is posted to my autoresponder, the autoresponder doesn't like hard carriage returns. Is it possible to keep all data entry on one line, so change something like this:

Join us for a brief burst of daily entertainment.

Jokes, toons, funny and strange links, news to amuse and more.

Join now, it's free.

to this when the user submits:

Join us for a brief burst of daily entertainment. Jokes, toons, funny and strange links, news to amuse and more. Join now, it's free.
Question by:lserrano
  • 2
  • 2
  • 2
  • +1

Expert Comment

ID: 10770136
Use join command

Here take a look at this


Instead of "," you use space " "

Expert Comment

ID: 10770142
Oops sorry , not space use VBcrlf

Author Comment

ID: 10770182
I'm looking for some JS to do this. Does anyone have a JS script to handle this?
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Expert Comment

ID: 10772692
Hi, I think you are looking for something like this:

This goes into the <head> section:

<script language="javascript">
function nocr()
 with (document.form1)
  for (var i=0; i < elements.length; i++)
   if (elements[i].type == 'textarea')
    elements[i].value=elements[i].value.replace(/\r\n/g,' ');
    elements[i].value=elements[i].value.replace(/\n/g,' ');

Change the <form> tag into:
<form name="form1" onsubmit='nocr()'>

This will change newlines to a space for all the TEXTAREAs in the form.

The two replace might seem redundant, but the first one works with IE, the second works with Netscape (at least in a not too old Netscape)

hope this helps

Assisted Solution

frox earned 50 total points
ID: 10772707
Oops, and remove the alert(), it was there for debugging purposes :-)
LVL 63

Accepted Solution

Zvonko earned 200 total points
ID: 10773406
My version is simmelar to frox's, except it is less hardcoded names:

<textarea name="UserInput" onChange="this.value=this.value.replace(/[\n\r]+/g,' ')">
<input type=submit>

Two notes: the onChange is always executed before submit. By onChange does the user also see the change on leaving the textarea for other elements input. If that confuses your user, then the same line can also be executed for all textareas in onSubmit, like frox did.
If you donot want the blanks for newlines, then add something else for your server side, for example a semicolon, a <br> or a special character.

My first guess was to use WRAP=SOFT
The description does state that browser is NOT sending the CR to server, but it seams not to be true.
Give that wrap also a try.
Like this:
<textarea name="UserInput" WRAP=SOFT>

Good luck,


Author Comment

ID: 10774995
Thanks Zvonko. You did it again. ;-)
LVL 63

Expert Comment

ID: 10775156



Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question