I would like to "join lines" in a textarea.
================================================
var el = document.getElementById("textarea");
oldText = el.value;
newText = oldText.replace("\n", "");
el.value = newText;
================================================
This extremely simple code works awesome in FF but noway in IE.
Also no errors in IE.
If I add:
================================================
var el = document.getElementById("textarea");
oldText = el.value;
newText = oldText.replace("\n", "");
alert(oldText);
alert(newText);
el.value = newText;
================================================
i can see that oldText and newText are the same.
The strange thing is that If I try:
alert(el.value.indexOf("\n")) it returns me the correct position.
Any help?
Regards.
--
Fabri
-Mandrake "A Poma', c'hai 'na faccia...!"
-Pomata "Sì, se ce n'avevo due già stavo all'università... sotto
spirito!" 7 1421
Fabri wrote: I would like to "join lines" in a textarea.
newText = oldText.replace("\n", "");
The problem is probably the different ways line breaks are encoded on
different platforms so try a regular expression
oldText.replace(/\r|\n|\r\n/, "")
--
Martin Honnen http://JavaScript.FAQTs.com/
Martin Honnen wrote:
<snip> so try a regular expression oldText.replace(/\r|\n|\r\n/, "")
Martin, it doesn't work :-(.
Thank you anyway.
I don't understand.
--
Fabri
-Mandrake "A Poma', c'hai 'na faccia...!"
-Pomata "Sì, se ce n'avevo due già stavo all'università... sotto
spirito!"
Fabri wrote: I would like to "join lines" in a textarea.
================================================ var el = document.getElementById("textarea"); oldText = el.value; newText = oldText.replace("\n", ""); el.value = newText; ================================================
This extremely simple code works awesome in FF but noway in IE.
Also no errors in IE.
If I add:
================================================ var el = document.getElementById("textarea"); oldText = el.value; newText = oldText.replace("\n", "");
el.value = el.value.replace( /\s+/g, ' ' );
All contiguous whitespace characters will be replaced by a single
space character.
[...] Any help?
I hope so :-)
--
Rob
Fabri wrote: oldText.replace(/\r|\n|\r\n/, "")
Martin, it doesn't work :-(.
Sorry, forgot the g flag
oldText.replace(/\r|\n|\r\n/g, "")
--
Martin Honnen http://JavaScript.FAQTs.com/
Thx Martin and Rob, googling I found this other solution:
el.value = escape(el.value);
for (i=0;i<el.value.length;i++){
el.value = el.value.replace("%0D%0A", "");
}
el.value = unescape(el.value);
Bye :-)
--
Fabrizio
Fabri wrote: I would like to "join lines" in a textarea.
================================================ var el = document.getElementById("textarea"); oldText = el.value; newText = oldText.replace("\n", ""); el.value = newText;;
and ...
newText = oldText.replace("\\n"," ");
by chance ?
but anyway ...
I think only 1st '\n' will be replace
if nothing work, try :
el.style.whiteSpace = 'nowrap';
(if return cariages are realy written that would no more work)
--
Stephane Moriaux et son [moins] vieux Mac
Fabri wrote: Thx Martin and Rob, googling I found this other solution:
el.value = escape(el.value); for (i=0;i<el.value.length;i++){ el.value = el.value.replace("%0D%0A", ""); } el.value = unescape(el.value);
Bye :-)
That may work, but the logic is absurd! It will loop through the
string as many times are there are characters - there may only be one
character to replace in 10,000.
And what is the point of escape/unescape? Please use either mine or
Martin's suggestion and save a zillion clock cycles - if for no other
reason that to save yourself a lot of typing.
:-)
--
Rob This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Julian |
last post by:
Hi
I am trying to update a date field in my table but some how this simple code
does not work, I know the select work because if I write the fields, it will
show the data from the table but why...
|
by: Joseph Barron |
last post by:
Here is a SIMPLE problem that I'm trying to solve.
It works in Netscape 6.2, but IE6 gives ""No such interface
supported."
Below are page1.htm and page2.htm .
In page1.htm, there are two...
|
by: JKop |
last post by:
Take the following simple function:
unsigned long Plus5Percent(unsigned long input)
{
return ( input + input / 20 );
}
Do yous ever consider the possibly more efficent:
|
by: 42 |
last post by:
I implemented a simple class inherited from Page to create a page
template. It simply wraps some trivial html around the inherited page,
and puts the inherited page into a form.
The problem I...
|
by: Claudio Grondi |
last post by:
In the process of learning about some deeper details of Python I am
curious if it is possible to write a 'prefix' code assigning to a and b
something special, so, that Python gets trapped in an...
|
by: Duncan |
last post by:
Hi
I'm learning c# 2.0 as I feel I need to be able to switch between vb & c#,
I'm just starting with a few simple examples and I've come across a problem.
I've got two forms ones an MDI parent &...
|
by: Evan |
last post by:
Hey, I posted this yesterday, but no one had any ideas? C'mon now, I
know this isn't that hard, i'm just a little new to javascript, and I
can't quite figure this out. I searched and searched to...
|
by: nw |
last post by:
Hi,
I previously asked for suggestions on teaching testing in C++. Based
on some of the replies I received I decided that best way to proceed
would be to teach the students how they might write...
|
by: galiorenye |
last post by:
Hi,
Given this code:
A** ppA = new A*;
A *pA = NULL;
for(int i = 0; i < 10; ++i)
{
pA = ppA;
//do something with pA
|
by: Chris M. Thomasson |
last post by:
I use the following technique in all of my C++ projects; here is the example
code with error checking omitted for brevity:
_________________________________________________________________
/*...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |