By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,165 Members | 853 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,165 IT Pros & Developers. It's quick & easy.

Scrolling textarea in Opera

P: n/a
Is there any way to scroll textarea (to the bottom row) from Javascript
in Opera? The

textarea.scrollTop=textarea.scrollHeight+textarea. scrollTop;

approach doesn't work, and there's so many notices that it doesn't all
over the net, that if there's any solution/workaround to this problem
on the net, it's unfindable.

Alternatively (my workaround) is there any way to reliably count lines
of text in Textarea so I could crop the start of the text so all of it
fits if more is added? (note: newlines, word wrap, tabs and optionally
variable size fonts should be taken into account. My current approach
is to split text at newlines and count each as
Math.ceil(line.length/textarea.cols) textarea lines but it doesn't take
into account long words triggering faster line wraps, tabs etc so
sometimes I overflow and bottom line gets hidden as more text is added.

Dec 22 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
One more quirk I recalled. <textarea cols=120; style="width: 20em;">
etc. Counting lines requires reliably counting columns and it seems
stylesheets can override the cols= parameter. I'd prefer my page to be
scalable and at least gracefully accept font resizing without creating
horizontal scrollbar on the browser window. Sorry for replying to self.

Dec 22 '05 #2

P: n/a
Followup-to set: comp.lang.javascript

bw****@gmail.com wrote :
Is there any way to scroll textarea (to the bottom row) from Javascript
in Opera? The

textarea.scrollTop=textarea.scrollHeight+textarea. scrollTop;
The scrollTop value can never be equalt to the scrollHeight: this is
impossible.
So to add the current scrollTop value to scrollHeight is even more
impossible.

approach doesn't work,
It never will in any browser. You're misunderstanding these 2
properties. You're mishandling these 2 properties.

http://www.gtalbot.org/BugzillaSecti...roperties.html
http://www.mozilla.org/docs/dom/domr...ollHeight.html
http://www.mozilla.org/docs/dom/domref/scrollTop.html
http://developer.mozilla.org/en/docs...t.scrollHeight
http://developer.mozilla.org/en/docs...ment.scrollTop
Opera 7, Opera 8 and Opera 9 do not render the css width and css height
correctly for textarea: it's wrongly implemented.
Bug 40 at this page:
http://www.gtalbot.org/BrowserBugsSection/Opera9Bugs/
https://bugzilla.mozilla.org/attachment.cgi?id=117564

and there's so many notices that it doesn't all over the net, that if there's any solution/workaround to this problem
on the net, it's unfindable.

Alternatively (my workaround) is there any way to reliably count lines
of text in Textarea so I could crop the start of the text so all of it
fits if more is added? (note: newlines, word wrap, tabs and optionally
variable size fonts should be taken into account. My current approach
is to split text at newlines and count each as
Math.ceil(line.length/textarea.cols) textarea lines but it doesn't take
into account long words triggering faster line wraps, tabs etc so
sometimes I overflow and bottom line gets hidden as more text is added.


You posted no url to show what you're proposing.

One last note: opera.beta is a newsgroup for testing with/commenting
on/reporting problems in/about beta releases.

Followup-to set: comp.lang.javascript

Gérard
--
remove blah to email me
Dec 22 '05 #3

P: n/a
Gérard Talbot wrote:
Followup-to set: comp.lang.javascript

bw****@gmail.com wrote :
textarea.scrollTop=textarea.scrollHeight+textarea. scrollTop;
The scrollTop value can never be equalt to the scrollHeight: this is
impossible.
So to add the current scrollTop value to scrollHeight is even more
impossible.


It just scrolls down by scrollHeight minus height.
True, plain textarea.scrollTop=textarea.scrollHeight; would suffice.
approach doesn't work,

It never will in any browser. You're misunderstanding these 2
properties. You're mishandling these 2 properties.


Have you tried? It works in MSIE and Firefox/Mozilla family just fine.
Try entering "400" in the fine document you've provided. :
http://www.mozilla.org/docs/dom/domref/scrollTop.html

Writing -anything- to scrollTop in Opera does nothing. Values well
within allowed range are disregarded just as well.
Opera 7, Opera 8 and Opera 9 do not render the css width and css height
correctly for textarea: it's wrongly implemented.


Thanks. Little in common with this problem (as I mentioned, no matter
what, scrollTop is ignored), but at least I won't bother with these
while calculating number of lines.
Alternatively (my workaround) is there any way to reliably count lines

You posted no url to show what you're proposing.


function out(txt) /* Write a string to output textarea. */
{
document.f.out.value += txt;
//the following is broken in Opera.
document.f.out.scrollTop = document.f.out.scrollHeight;
if(Opera){ // defined elsewhere
document.f.out.value=crop(document.f.out.value);
}
}

function crop(txt) /* We can't scroll textarea in Opera, */
{ /* so let's at least make the text fit */

while( countlines(txt) >= document.f.out.rows){
txt=txt.slice(10); // remove 10 chars from front, try again
};
return txt
}

/* estimating the number of lines txt takes in textarea. */
function countlines(txt)
{
var cols=document.f.out.cols;
var count=0;

var ln=String(txt).split('\n');
for(var i=0;i<ln.length;i++){
/* each logical line takes at least one physical line.
* Every /cols/ chars is a physical line, and a tab is 8 chars.
* tabs are common and we'd better arrive at more than less what
* really is displayed. */
count += Math.ceil( (ln[i].length + 8.0) / cols );
}
return count;
}

Dec 22 '05 #4

P: n/a
bw****@gmail.com wrote :
Gérard Talbot wrote:
Followup-to set: comp.lang.javascript

bw****@gmail.com wrote :
textarea.scrollTop=textarea.scrollHeight+textar ea.scrollTop;
The scrollTop value can never be equalt to the scrollHeight: this is
impossible.
So to add the current scrollTop value to scrollHeight is even more
impossible.

It just scrolls down by scrollHeight minus height.


Ok, so why don't you use this calculation instead? If you know this is
the correct code, then why not use it? What's wrong with using the
correct code to do this?
True, plain textarea.scrollTop=textarea.scrollHeight; would suffice.

It works but it's still a wrong calculation. scrollTop value is never
the scrollHeight value; never.
approach doesn't work,
It never will in any browser. You're misunderstanding these 2
properties. You're mishandling these 2 properties.

Have you tried? It works in MSIE and Firefox/Mozilla family just fine.


It is a wrong calculation. You are relying on error correction mechanism
here. Next week, next month, next year, whatever, browser manufacturers
may change the error correction mechanism and report an error in the
javascript console. Your code is not correct and relies on a specific
error correction mechanism.
Try entering "400" in the fine document you've provided. :
http://www.mozilla.org/docs/dom/domref/scrollTop.html
Try entering 1000: it's still wrong.

Writing -anything- to scrollTop in Opera does nothing. Values well
within allowed range are disregarded just as well.

Opera 7, Opera 8 and Opera 9 do not render the css width and css height
correctly for textarea: it's wrongly implemented.

Thanks. Little in common with this problem (as I mentioned, no matter
what, scrollTop is ignored), but at least I won't bother with these
while calculating number of lines.

Alternatively (my workaround) is there any way to reliably count lines


You posted no url to show what you're proposing.

function out(txt) /* Write a string to output textarea. */


You pasted just functions: I was expecting an url showing the problem or
what you were proposing.

Gérard
--
remove blah to email me
Dec 23 '05 #5

P: n/a

Gérard Talbot napisal(a):
bw****@gmail.com wrote :
Gérard Talbot wrote:
So to add the current scrollTop value to scrollHeight is even more
impossible.

It just scrolls down by scrollHeight minus height.


Ok, so why don't you use this calculation instead? If you know this is
the correct code, then why not use it? What's wrong with using the
correct code to do this?


How much is 400px - 8em ?
(as I mentioned, my page is scalable.)
Try entering "400" in the fine document you've provided. :
http://www.mozilla.org/docs/dom/domref/scrollTop.html


Try entering 1000: it's still wrong.


which doesn't mean it doesn't work. And since scrollTop is not a part
of any standard or recommendation, its support may cease in any new
browser revision altogether, so by your reasoning using it at all is
wrong. I'm depending on safety mechanisms of poorly docummented and
unstandarized feature. I'm fully aware it's stepping on thin ice,
that's why I asked for potentially better solution.
function out(txt) /* Write a string to output textarea. */


You pasted just functions: I was expecting an url showing the problem or
what you were proposing.


if you insist...

http://www.kurs.horsesport.pl/inne/testcase.html

Dec 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.