View Full Version : text cursor on a textarea
jolietjake
10-28-2002, 11:55 AM
Hello, here's a problem:
I have a textarea , where the user can write some text. The user have some buttons that writes some common text in the textarea, but when javascript runs the focus() function to return to the textarea, it places the text cursor on the begin of the text.
How can I place the text cursor at the end? Can I put it in any place? how?
Thanks again.
JolietJake. Master of Blues & Rythm.:cool:
beetle
10-28-2002, 02:54 PM
I believe this is related to some previous topics (http://www.codingforums.com/search.php?s=&action=showresults&searchid=34879&sortby=lastpost&sortorder=descending) on reading/setting caret position. If I'm not mistaken, at the time we determined it was not possible because the text-range object that is used to do such inserts relies on pixel measuerments read from the current selection, and was not based on actual positions amongst the characters in the textarea.
So, in short. Don't think you can do this.
Feel free to read through the posts in the link above
// pretend textArea is a reference to the textarea element
textArea.setSelectionRange(textArea.value.length, textArea.value.length);
You gotta love Gecko. :)
beetle
10-28-2002, 04:03 PM
Originally posted by jkd
// pretend textArea is a reference to the textarea element
textArea.setSelectionRange(textArea.value.length, textArea.value.length);
You gotta love Gecko. :) "Gotta love DOM2" is more apropos, don't you think?
Thanks jkd...after posting above I begain to wonder if the range interface could handle it...
No, Gecko-only. This is not a method defined in the DOM2 HTML specs.
beetle
10-28-2002, 04:25 PM
Originally posted by jkd
No, Gecko-only. This is not a method defined in the DOM2 HTML specs. Really? I thought Gecko was void of any "this browser only, non W3C" type stuff. Hmm.
Originally posted by beetle
Really? I thought Gecko was void of any "this browser only, non W3C" type stuff. Hmm.
Think again. :)
There is nothing wrong with having "extras" - as long as it has the fundamentals down pat. Internet Explorer is extremely lacking in one area, and has more than enough in the other, while Mozilla is plentiful in both.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.