473,513 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Scrolling textarea in Opera

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
5 4533
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
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
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5200
by: Charles | last post by:
Hi folks, I am desperatly looking for a WYSIWYG HTML editor for a textarea, using JavaScript and that'll work with Opera. I want this editor to use for a webmail program in PHP, and allow users...
7
1944
by: Pete | last post by:
I'm working (playing) on a mouse following script. Yes, the sort no one likes but I'm having great fun tinkering with it - sad. Anyway, if there's enough page content to cause scrolling and I...
4
16663
by: Csaba Gabor | last post by:
What I'd like to do is to be able to set the font of a textarea element to the same font that another element is using (say, for example, an <INPUT type=text ...> element, but if that's a no go,...
6
4562
by: stuart | last post by:
I have two textareas on a HTML page. If a user scrolls in one textarea I want the other textarea to scroll as well. In otherwords I want both textareas to scroll up and down in unison. Can...
5
3618
by: Mark | last post by:
How do I scroll two textareas in sync with FireFox/Mozilla? The IE solution has been posted before by Martin Honnen.
2
11201
by: Mark Szlazak | last post by:
The following code fails in Firefox to get at selected text in the right-side textarea. Any help would be appreciated. <html> <head> <script> var agt = navigator.userAgent.toLowerCase();...
4
7740
by: Keith Bentrup | last post by:
Hi all, I wrote a simple search function to find text in a textarea where not all the text is visible (ie. the text box displays 10 lines but there may be more than 1000 lines to search). I can...
5
1516
by: K. | last post by:
Hi! I have such code: <textarea name="text_field">very long text</textarea> I have filled in the value of textarea field. This value is a very long string. I would like to scroll this...
1
2266
by: Anirhudra | last post by:
I have a TextArea and there I want to write my tracefile info .... but I want to see the scrolling automatically and to see the last line of my tracefile info within this TextArea without...
0
7175
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...
0
7391
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,...
1
7120
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
7542
tracyyun
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...
0
5697
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,...
0
4754
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
3247
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3235
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.