View Full Version : focus cursor at certain position inside textarea

07-08-2003, 01:23 AM
is there a way to set the cursor to be at a certain point in a text area when the page is loaded?

i have a prefilled text area and want the cursor to show up after the text inside of it.

<form name="form1" id="form1">
<textarea name="field1" cols="60" rows="10" id="field1">I want the cursor to show up after this line. </textarea>

07-08-2003, 01:57 AM
Assume "tarea" is a reference to the textarea:

tarea.setSelectionRange(tarea.length, tarea.length);

This is for Gecko-based browsers, such as Mozilla, Firebird, NS7, Camino, etc.

There is some way using a TextRange object in Win/IE of doing this, but I don't recall it off the top of my head.

07-08-2003, 02:05 AM
thanks. IE is actually the browser that i'm targeting. if anyone knows how to do this in IE, i'd appreciate it.

07-08-2003, 10:46 AM
There's method setEndPoint but... hm, I never use it... I am not sure that it might help you...