Carriage return inefficiency in a textarea control

P

Patrick

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>
 
L

Lasse Reichstein Nielsen

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
 
P

Patrick

It appears, however that textareas don't handle
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.
 
L

Lasse Reichstein Nielsen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,282
Latest member
RoseannaBa

Latest Threads

Top