473,473 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Carriage return inefficiency in a textarea control

I'm developing an application which requires
a textarea to display large amounts of data.
I'm storing the information in an array and then
using join to dump the contents into the textarea.
It appears, however that textareas don't handle
carriage returns very well as illustrated by the following code.
If would appreciate if anyone knows the reason for this behavior
and a possible workaround.

<HTML><HEAD>
<TITLE>Textarea</TITLE>
<SCRIPT>
var arr= new Array;
function GenString(s){
arr.length=0;
for (var i=0;i<5000;i++)
arr[arr.length] = i + ' = [abcdefghijklmnopqrstuvwxyz]'
var d = new Date();
if (s=='||')form1.textarea1.value=arr.join('||')
else form1.textarea1.value=unescape(arr.join('\n'))
var d1= new Date()
alert((d1-d)/1000 + ' seconds' + '\n' + 'Textarea length= ' +
form1.textarea1.value.length);
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="form1">
<TEXTAREA ROWS="10" COLS="40" NAME="textarea1"></TEXTAREA>
<BR><INPUT TYPE="button" VALUE="Generate || string" NAME="button1"
ONCLICK="GenString('||')">
<INPUT TYPE="button" VALUE="Generate \n string" NAME="button1"
ONCLICK="GenString('\n')">
</FORM>
</BODY>
</HTML>
Jul 20 '05 #1
3 7941
pa**@ceposystems.com.au (Patrick) writes:
It appears, however that textareas don't handle
carriage returns very well as illustrated by the following code.
If would appreciate if anyone knows the reason for this behavior
and a possible workaround.


You failed to tell us what the behavior is, what you expected, and
which browser exhibits the bad behavior.

Is the problem that the string joined with "\n" takes ~four times longer
to insert into the textarea?
In that case, it has nothing to do with Javascript, but is an artifact of
the underlying implementation of text areas. Any solution would include
not using a text area.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
> > It appears, however that textareas don't handle
carriage returns very well as illustrated by the following code.
If would appreciate if anyone knows the reason for this behavior
and a possible workaround.


You failed to tell us what the behavior is, what you expected, and
which browser exhibits the bad behavior.

Is the problem that the string joined with "\n" takes ~four times longer
to insert into the textarea?
In that case, it has nothing to do with Javascript, but is an artifact of
the underlying implementation of text areas. Any solution would include
not using a text area.
/L


Lasse

Thanks for your reply.

To clarify: I'm experiencing this behavior on IE5.0. (I'm actually
developing for the Pocket PC version of IE which in this case shows
the same behavior as IE5.0). When you run the supplied code snippet in
IE5 - the double pipe "||"
renders the entire string to the text area in approx. .1 of a second
as opposed to the "\n" version which takes 7.5 seconds - for the same
sized string. I've run the code on some other browsers with the
following results:
Browser "||" "\n"
IE5.0 0.12 sec 7.5 sec
IE6.0 0.15 sec 0.7 sec
Opera7.11 12 sec 12 sec
NN7.02 4.5 sec 12 sec

As you see quite a difference between browsers and in some instances
the render times for the two strings. What is even more curious is
that Netscape reports a different string size ie. 178889 for the "\n"
option as opposed to 183888 for the "||" option. I tend to agree with
you that this text area behavior seems to be due to the underlying
browser implementation - if there are any solutions that would prevent
this behavior - is another question.
Jul 20 '05 #3
pa**@ceposystems.com.au (Patrick) writes:
When you run the supplied code snippet
in IE5 - the double pipe "||" renders the entire string to the text
area in approx. .1 of a second as opposed to the "\n" version which
takes 7.5 seconds - for the same sized string. I've run the code on
some other browsers with the following results: Browser "||" "\n"
IE5.0 0.12 sec 7.5 sec
IE6.0 0.15 sec 0.7 sec
Opera7.11 12 sec 12 sec
Opera 7.2 is faster, and gives results similar to IE 6.
NN7.02 4.5 sec 12 sec

As you see quite a difference between browsers and in some instances
the render times for the two strings.
Yes, quite a difference. Are IE 5 and IE 6 running on different
operating systems? Because I would expect the operating system to be
the important factor if the browser uses standard system widgets
(which I don't think Mozilla/NN7 does).
What is even more curious is that Netscape reports a different
string size ie. 178889 for the "\n" option as opposed to 183888 for
the "||" option.
That is probably because Mozilla uses UNIX End-of-line encoding (one
newline, 0x0a) and the other browsers uses DOS/Windows EOL (carrige
return+newline, 0x0d 0x0a).
I tend to agree with you that this text area behavior seems to be
due to the underlying browser implementation - if there are any
solutions that would prevent this behavior - is another question.


I doubt it.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: yawnmoth | last post by:
so... i'm trying to remove all carriage returns in the input i get from GET, and am trying to replace them with three dots... however, this never seems to work... i'm still getting carriage...
1
by: Augustus | last post by:
Hiya, I have a form with a <textarea></textarea> to receive user input. This input is then stored in a database and sent by fax... I need to be able to remove the carriage returns (enter...
2
by: Karthik.S | last post by:
I have a text area in my webpage where i allow people to format their data in to multiple paragraphs. I store this data in the database and display it in a similar textarea to keep the formatting...
8
by: Steven | last post by:
i need to force a carriage return with a textarea field at X number of characters. anybody know how to do this? tks
4
by: Les Juby | last post by:
Can someone please help with a suggestion as to how I can keep the formatting (carriage returns) that the user enters into a memo field and then display that later. I figured I might be able to...
1
by: VMI | last post by:
If I want to separate a string in a web textbox so that it takes several lines, how can do it? In a Windows textbox, I only needed to add the "\r\n" to the string for the carriage return....
7
by: mattrapoport | last post by:
I have a page with a div on it. The div displays a user comment. When the user logs into this page, their current comment is pulled from a db and displayed in the div. The user can edit the...
8
by: crjunk | last post by:
I have a field in a SQL Server table named DetailedDescription that is a varchar. If the user adds/edits a detailed description, they do so in a MulltiLine TextBox control. Therefore, they are...
1
by: Blue | last post by:
This JS limits the input characters into the form. How do I modify it so that it also allows CARRIAGE RETURN and BACKSPACE (for making text correction)? Due to the template engine I am using, I...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.