473,779 Members | 1,867 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.scroll Top=textarea.sc rollHeight+text area.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 4583
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.javas cript

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

textarea.scroll Top=textarea.sc rollHeight+text area.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 misunderstandin g 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.javas cript

Gérard
--
remove blah to email me
Dec 22 '05 #3
Gérard Talbot wrote:
Followup-to set: comp.lang.javas cript

bw****@gmail.co m wrote :
textarea.scroll Top=textarea.sc rollHeight+text area.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.scroll Top=textarea.sc rollHeight; would suffice.
approach doesn't work,

It never will in any browser. You're misunderstandin g 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(docu ment.f.out.valu e);
}
}

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(1 0); // 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.co m wrote :
Gérard Talbot wrote:
Followup-to set: comp.lang.javas cript

bw****@gmail. com wrote :
textarea.scr ollTop=textarea .scrollHeight+t extarea.scrollT op;
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.scroll Top=textarea.sc rollHeight; 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 misunderstandin g 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.

Alternativel y (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.co m 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
5227
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 to send HTML email. All HTML editors I found out on the web work for most browsers except Opera. Does any of you guys know of an Opera-friendly editor? That would be great... Thanks,
7
1996
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 want the objects (colored divs) to scroll with the mouse in Opera 6. I give the mouse y coords (-) window.pageYOffset and the objects (+) window.pageYOffset. However, in Opera 7 it doesn't work. Only the following objects need (+)...
4
16723
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, then a generic element's font will do OK, too. What's the correct way to do this, please (so that it will also work for IE 6)? The motivation for this is that I have some text on the screen and I want to insert a textarea element between the...
6
4638
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 anyone help. Thanks Stuart
5
3670
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
11237
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(); var safari = ((agt.indexOf('safari') != -1) && (agt.indexOf('mac') != -1))? true:false; var opera = (window.opera)? true:false;
4
7807
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 find the text and select it using the function below, BUT I can't figure out how to have the textarea automatically scroll to the selection in Firefox. Any ideas or suggestions? function search(needle,haystack,start) { var element =...
5
1531
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 textarea field into the end.
1
2301
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 scrolling. Here is my HTML file ... FORM name="TraceFile"> <TextArea Name = "commentbox" ROWS="8" COLS="70"></TextArea>
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10074
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9930
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7485
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5373
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
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.