473,840 Members | 1,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Textarea - Mozilla

Hi,

FAQ tells how to insert (or replace0 a text at a caret position in
Mozilla (and same works for Opera 8+), for example, at
http://www.faqts.com/knowledge_base/view.phtml/aid/1661
it talks about that -
....
textControl.set SelectionRange( oldSelectionSta rt + newText.length,
oldSelectionSta rt + newText.length) ;

But this has a problem - if my Textarea is say 10 lines long
and is _full_ and I am trying to insert - programmaticall y -
some text down below, say in line #12:

I can NOT see what my Javascript code inserts -
the above cited textControl.set SelectionRange( )
sets the screen to the very beginning of my Textarea, to the line #1,
so line #12 content goes out of sight...

Is it solvable? May be I can somehow set a focus onto current
caret position, i.e. make line #12 visible after the
insertion/replacement?

Thanks,
Paul
Aug 1 '05 #1
9 2766
Any one?

May be one of the auhtors of that entry of the FAQ?
--
Regards,
Paul
Aug 4 '05 #2
Paul Gorodyansky said the following on 8/3/2005 8:39 PM:
Any one?
Anyone what? Quote what you are replying to and that becomes a moot issue.
May be one of the auhtors of that entry of the FAQ?


What FAQ? The c.l.j FAQ? The c.i.w.a.s FAQ? The
Humpty-Dumpty-Fell-Off-The-Wall FAQ?

If you want the cursor at the end of the textarea, try grabbing the
textarea's value, set it to '' to clear it, then set it back to what it
was....

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Aug 4 '05 #3
Hi,

Randy Webb wrote:

Anyone what? Quote what you are replying to and that becomes a moot issue.
Why 'moot'? It's easily reproducible - just using the examples
on the page I mentioned -
http://www.faqts.com/knowledge_base/view.phtml/aid/1661
May be one of the auhtors of that entry of the FAQ?
What FAQ? The c.l.j FAQ? The c.i.w.a.s FAQ? The
Humpty-Dumpty-Fell-Off-The-Wall FAQ?


No, I did specify which FAQ -
http://www.faqts.com/knowledge_base/view.phtml/aid/1661

If you want the cursor at the end of the textarea, try grabbing the
textarea's value, set it to '' to clear it, then set it back to what it
was....


No, the cursor (and caret) _is_ at the end of the text area
(or at the place where we insert some text), the problem is
that we can NOT see it - again, easy to see on any example
of
http://www.faqts.com/knowledge_base/view.phtml/aid/1661
if TEXTAREA is used...
--
Regards,
Paul
Aug 4 '05 #4
Hi,

Here is the code of
http://www.faqts.com/knowledge_base/view.phtml/aid/1661 -
with TEXTAREA of 3 lines long, so it's EASY to see that
lines after #3 have hte problem I explained - everything works OK,
but in Mozilla/Firefox we can not see that:
http://www.geocities.com/paulgor1/js.htm

--
Regards,
Paul
Aug 4 '05 #5
Paul Gorodyansky said the following on 8/4/2005 12:36 PM:
Hi,

Randy Webb wrote:
Anyone what? Quote what you are replying to and that becomes a moot issue.

Why 'moot'? It's easily reproducible - just using the examples
on the page I mentioned -
http://www.faqts.com/knowledge_base/view.phtml/aid/1661


In the post I replied to, there is no reference to *any* FAQ. I suggest
you re-read your post that I replied to.
May be one of the auhtors of that entry of the FAQ?


What FAQ? The c.l.j FAQ? The c.i.w.a.s FAQ? The
Humpty-Dumpty-Fell-Off-The-Wall FAQ?

No, I did specify which FAQ -
http://www.faqts.com/knowledge_base/view.phtml/aid/1661


In the post I replied to, there is no reference to *any* FAQ. I suggest
you re-read your post that I replied to.
If you want the cursor at the end of the textarea, try grabbing the
textarea's value, set it to '' to clear it, then set it back to what it
was....

No, the cursor (and caret) _is_ at the end of the text area
(or at the place where we insert some text), the problem is
that we can NOT see it - again, easy to see on any example
of
http://www.faqts.com/knowledge_base/view.phtml/aid/1661
if TEXTAREA is used...


See how easy that was? You quoted what you were replying to, and it all
makes sense now. Well, not really but it almost does.

I won't even ask why you think you need to do that onKeyUp, you simply
set an onChange that will convert the entire textarea's content to upper
case.
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Aug 4 '05 #6
Randy Webb wrote:


I won't even ask why you think you need to do that onKeyUp, you simply
set an onChange that will convert the entire textarea's content to upper
case.


Some other examples on
http://www.faqts.com/knowledge_base/view.phtml/aid/1661
answer that - for example they have an example when a user types
German accented letters on a regular German keyboard, but what goes
to the screen is another representation of such as letter -
different for different letters.

That is, the whole point is to be able to send to screen what
we want when a user presses a keyboard key...

Anyway, I made a small test page for my question - easy to see
what the issue is:

Here is the code of
http://www.faqts.com/knowledge_base/view.phtml/aid/1661 -
with TEXTAREA of 3 lines long, so it's EASY to see that
lines after #3 have the problem I explained - everything works OK,
replacement goes as designed, but in Mozilla/Firefox we can
not see that, it's out of sight:
http://www.geocities.com/paulgor1/js.htm

--
Regards,
Paul
Aug 5 '05 #7
In a Newsreader earlier messages of this thread could be not present,
so here is the full set:
http://groups.google.com/group/comp....14e34bffb016f9
--
Regards,
Paul
Aug 5 '05 #8


Paul Gorodyansky wrote:

Here is the code of
http://www.faqts.com/knowledge_base/view.phtml/aid/1661 -
with TEXTAREA of 3 lines long, so it's EASY to see that
lines after #3 have the problem I explained - everything works OK,
replacement goes as designed, but in Mozilla/Firefox we can
not see that, it's out of sight:

http://www.geocities.com/paulgor1/js.htm


The code simply uses the setSelectionRan ge API that Mozilla exposes for
text controls, in your test case it looks as if that function correctly
places the caret in the textarea but the textarea is not scrolled to the
line where the caret is set.
It is not easy to correct from the JavaScript code itself as obviously
what you want to happen is that setSelectionRan ge, a native function
implemented in Mozilla, itself scrolls to the line where the caret is.
In Mozilla it is possible to scroll textareas by setting
textarea.scroll Top
so if you want to fix that with JavaScript you would need to scroll to
the intended line by setting textarea.scroll Top as needed.
As a start I would try to change

textControl.val ue =
textControl.val ue.substring(0, oldSelectionSta rt) +
newText +
textControl.val ue.substring(ol dSelectionEnd);
textControl.set SelectionRange( oldSelectionSta rt + newText.length,
oldSelectionSta rt + newText.length) ;

to

var scrollTop, scrollLeft;
if (textControl.ty pe == 'textarea' && typeof textControl.scr ollTop !=
'undefined') {
scrollTop = textControl.scr ollTop;
scrollLeft = textControl.scr ollLeft;
}
textControl.val ue =
textControl.val ue.substring(0, oldSelectionSta rt) +
newText +
textControl.val ue.substring(ol dSelectionEnd);
if (typeof scrollTop != 'undefined') {
textControl.scr ollTop = scrollTop;
textControl.scr ollLeft = scrollLeft;
}
textControl.set SelectionRange( oldSelectionSta rt + newText.length,
oldSelectionSta rt + newText.length) ;

That simply tries to store the current scroll position before the value
is changed (which makes the textarea lose its scroll position in
Mozilla), then changes the value as before, then tries to restore the
scroll positions and then sets the caret as before.

Try whether that helps and report back.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 5 '05 #9
Hi,

Martin Honnen wrote:
...

Try whether that helps and report back.


Thanks, Martin, it works Ok now, I created test file 1:
http://www.geocities.com/paulgor1/js1.htm

By the way, just FYI - Opera 8 - which uses successfully
the same code as Mozilla for such things
(in my own code I have if (Opera) Br == "NN"; // same as Mozilla)

did not have such problem, that is, it worked Ok even
before the fix you suggested...
--
Regards,
Paul
Aug 5 '05 #10

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

Similar topics

12
2590
by: Phil Powell | last post by:
The customer made a wild request: they want on their admin panel a textarea that will display an existing resume. This textarea, however, must have a dynamic width, one that "fills the screen width of any sized screen". Sorry but I cannot fathom how to do this! <textarea name="resume" cols="108" rows="29" wrap="physical><?= $resume ?></textarea>
3
14500
by: phil_gg04 | last post by:
Dear CSS Experts, I want to make a textarea fill all the available width. This is something I've done before but mostly by trial and error; now I want to understand what is going on. So I try: textarea { margin-left: 0; margin-right: 0; width: auto;
4
5898
by: joebob | last post by:
The following script if run in Internet Explorer should display a thumbview of a webpage that you point it to. To test it, replace test.htm with a valid html file. The problem I'm having is that I can't get onclick to fire on the rendered Thumbview object. What's strange is that onmouseover fires. Can anyone see a way? <html><head><title>test</title></head> <body onload="Init()">
6
4643
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
4
1874
by: J. VerSchave | last post by:
I am curious if there is a way to handle this... maybe with Javascript... Is there a way to set a TEXTAREA field so that the tab key on the user's keyboard will create a tab within the text rather than tabbing to the next field on the form? Thanks. -j
2
3116
by: Peter Wright | last post by:
Hi all. Hopefully this should demonstrate the problem I'm having: http://flooble.net/~pete/focus-problem-demo/ (I'm testing it in Mozilla only, but I'm not sure if it's actually a Mozilla-only problem) I'm capturing the focus and blur events for the document, updating a
8
5566
by: Csaba Gabor | last post by:
Is there any way in Mozilla/Firefox to add an event listener to all textarea elements? Something along the lines of HTMLTextAreaElement.prototype.onkeydown = function() {alert('mom');} only it should work, too. Or is my only solution to loop through each one and use ..addEventListener? And then trap for any DOM modifiactions in case new ones are created. Thanks,
1
7490
by: tranky | last post by:
Hola boys, i've a question for you! It's possible to highlight some text inside a textarea? (not all text, but a portion!) For example, i've this text inside a textarea. INSERISCI TESTO i want to highlight only "INSERISCI TESTO". It, must be an universal function, so i can use it also in other cases, for example when tag are and .
2
3159
by: swethak | last post by:
Hi, I am getting the problem the problem with google map in Internet Explorer. This map worked fine in mozilla . When i opened the same map in Internet Explorer i am getting the error message as in alert box as " Internet Explorer cannot open the Internet site http://google.citycarrentals.com.au/viewalllocations.php . Operation aborted". It is working in Mozilla . Here i mentioned my code . I am facing this problem several...
0
9698
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
10916
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...
0
10299
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
9436
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
7836
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
7022
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
5684
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...
2
4071
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3136
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.