Solved

Delete carriage return in string

Posted on 2004-08-06
5
1,007 Views
Last Modified: 2007-12-19
I would like a javascript function which will replace a carriage return with an empty space.
Thanks
0
Comment
Question by:MichaelMullin
[X]
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
5 Comments
 
LVL 25

Accepted Solution

by:
devic earned 50 total points
ID: 11739791
try this:
=======
<form>
<textarea name=t style=width:300px;height:300px></textarea>
      <input type=button value=OK onclick='this.form.t.value=this.form.t.value.replace(/\r\n/g,"")'>
</form>
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11739876
Hi

devic's should work. Of course, you can be more compliant by including all of his attributes in quotes, but it'll work. I'm thinking you want it to be for Unix, am I right? Well, if you only want to delete the \r, use:

this.form.t.value=this.form.t.value.replace(/\r/g,"") which is basically the same as devic's above

Regards,
Zyloch
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11742010
Small improvement of devic's code would be also to replace [\r\n]  for example on Linux\Unix\Mac browsers.

Like this:
<form>
<textarea name=t style=width:300px;height:300px></textarea>
     <input type=button value=OK onclick='this.form.t.value=this.form.t.value.replace(/[\r\n]/g,"")'>
</form>

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

759 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