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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cursor Pos

Status
Not open for further replies.

chuckyarg

Programmer
Joined
Jan 9, 2006
Messages
4
Location
US
Hi

Does anybody know how to get the current cursor position in an input type='text'?

Thankd
Chucky
 
I don't think there's either an easy or reliable way, but if you want hard and unreliable, you can keep track of the value in the text box by checking it after each onkeyup event. Compare the current value to the last value and assume the cursor is after the added letter (or in place of the deleted letter).

If the value is the same from one instance to the next, then the user may have hit HOME, END, ->, <-, the up or down arrows, the tab key, a function button, ... You can test for these but it starts to get really complicated.

A perfectly accurate but unfriendly method is to:

document.forms['myForm'].elements['myText'].value = "";

Now you know where the cursor is! It's at 0! :)

Maybe somebody's gone to all the trouble to write something along the lines of my first idea. Have you Googled this topic?

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Hi

Does somebody know how to get the stutus of the insert mode with Javascript?

Thanks
 
I found a way to do it

Just for you information

var obj = document.body.createTextRange();
return obj.queryCommandValue('OverWrite');

It will return true when is OverWrite mode, and false when is Insert mode.

Thanks
 
It will return true when is OverWrite mode, and false when is Insert mode.
And have the lovely drawback of only working in IE.

-kaht

How much you wanna make a bet I can throw a football over them mountains?
sheepico.jpg
 
I know, so far is what I have found. Does somebody has other solution?
 
I don't have an answer for the status of the insert button, but this link will help with your original question. Additionally, when you have a new question that is completely seperate from what you've already asked try to keep them in seperate threads. You'll have a lot more success getting responses that way.


-kaht

How much you wanna make a bet I can throw a football over them mountains?
sheepico.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top