473,378 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Using js to scroll to caret pos in textarea in Firefox

Hey Everyone,

I'm trying to scroll a textarea to the position of the caret which is
below the visible area of the textarea in firefox. I have code which
works in IE but the code I use for firefox creates an elastic band
effect. The textarea quickly scrolls down then bounces up to the top,
no matter what I try.

Has anyone run into the same difficulty? How did you solve it?

This is the code I'm currently using:
Note: inpu = textarea

var ev = document.createEvent ('KeyEvents');
ev.initKeyEvent('keypress', true, true, window,false, false, false,
false, 0,inpu.value.charCodeAt(pos-1));
inpu.dispatchEvent(ev); // causes the scrolling
inpu.setSelectionRange(pos, pos);

Thanks for your help!

Randy

Nov 21 '06 #1
2 6484


On Nov 21, 2:46 pm, "rjonasz" <rjon...@gmail.comwrote:
Hey Everyone,

I'm trying to scroll a textarea to the position of the caret which is
below the visible area of the textarea in firefox. I have code which
works in IE but the code I use for firefox creates an elastic band
effect. The textarea quickly scrolls down then bounces up to the top,
no matter what I try.
Well the solution to my problem was too simple. All I needed to do is
call

setTimeout("document.forms[0].txtarea.scrollTop="document.forms[0].txtarea.value.length",0);

after i updated the textarea. Man there are days when the feeling of
being dumb is matched by behaviour. :)

Cheers,

Randy

Nov 22 '06 #2
rjonasz escreveu:
setTimeout("document.forms[0].txtarea.scrollTop="document.forms[0].txtarea.value.length",0);
This doesn't make sense, scrollTop is measured in pixels, do you want to
scroll the textarea to the end? If yes, assign to the scrollTop, the
value of the scrollHeight property.
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Nov 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Zbigniew Braniecki | last post by:
Hello. I'm looking for any way to grab caret position in textarea (start, end - if selection) in Internet Explorer. Is it at all possible? Also any idea for doing it in Opera, KHTML would be...
7
by: Mel Weaver | last post by:
Hello, How do you scroll to the bottom of a multiline textbox in code? Mel
6
by: Rachel Suddeth | last post by:
I have the index of a line in the Lines array of a RichTextBox. I would like to have it scroll so that line displays at the top. Is there no way to do this? The only way I can see to make it...
1
by: j_macaroni | last post by:
I found this code to calculate the caret position in a textarea. In the script getCaret below, I pass it the TextArea1 element. It seems to work until you press a CR. In which case you get the...
7
by: =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?= | last post by:
I need to emulate the missing "maxlegth" attribute in "textarea" fields but all my Google searches either lead to obsolete scripts that overwrite the "value" property (thus losing caret position)...
5
by: konryd | last post by:
I want to know when a user scrolls the textarea. Since there is no such an event, I need to scroll all the ways scrolling might be invoked, that is: * by pressing keys * by moving mouse * by...
3
by: ReGenesis0 | last post by:
Is it possible to determine the caret position, in terms of x/y pixels, within a textarea? (I want to have a suggestion box pop up under where you're typing... so i need to determine where you are...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.