Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Cursor Position (IE only) 2

Status
Not open for further replies.

jaredn

Programmer
Sep 1, 1999
1,506
US
Not sure if anyone is interested, but this should allow you to set the cursor position in any text input element ( textarea, various input types, others? ).

/*
obj is the element object
pos is the position in the string the cursor should appear
*/
function setCursor(obj,pos)
{
if(pos<0) throw new Error(666,&quot;Invalid argument in setCursor.&quot;)

var r = obj.createTextRange();
r.moveStart(&quot;character&quot;,pos-1);
r.collapse();
r.moveEnd(&quot;character&quot;,pos==0?0:1);
r.text = r.text;
r.select()
}
jared@eae.net -
 
nice, jared. If only NS would get their *>?! together, all would be good in the world.

;-)
penny.gif
penny.gif
 
Its Fandu Man !!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top