473,729 Members | 2,176 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 4580
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
5225
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
1994
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
16718
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
4636
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
3667
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
11234
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
7801
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
1528
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
2299
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
8763
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
9288
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9154
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
6026
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4531
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...
0
4797
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3240
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
2692
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2166
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.