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

The Text Cursor in a Text Box (Asked Again)

Status
Not open for further replies.

fmh

Technical User
Jan 19, 2003
4
US
Hi again!
Let's suppose that we have a text box and a button in an HTML page. I want to do the following: When the button is clicked, a certain string (let's say 'Hello') will appear in the text box, but at the current location of the text cursor, and without deleting any previously entered text. For example, if the content of the text box is 'Hi |all' - where the bar '|' represents the text cursor - the content should become 'Hi Helloall', after pressing the button. Tough, isn't it? Again, any help is highly appreciable.
 
This is just the outline of how I would go about doing this, without having much time to test my theory:

1. use the onchange/onkeyup event of the text box to set a JavaScript variable to the position of the cursor.
2. Use the onclick event of the button to add the text to the text box, at the saved position, by way of a JavaScript function.

If you want me to look into the coding to do this, let me know, by way of a reply post.

Simon
 
Thank you swilliams. The problem is how to get the position of the text cursor in the text box. I appreciate your help.
 
You cannot retreieve the cursor position jared@aauser.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top