I have a text area. I would like to be able to click the cursor into this text area (full of text) and then know (with an alert for now) how many characters there are from the start of the text area up to my cursor.
I found this on DevGuru.com, I think it could be a hint in the right direction.
select Method
This method is used to select and highlight all or a portion of a text in a Textarea element. Used in conjunction with the focus method, this makes it easy to prompt the user for input and places the cursor in the correct place.
Basically the user has to highlight the text from where they place the cursor back to the beginning of the field. Javascript code then counts the amount of characters highlighted and places that count value into another field.
This allows me to have a view that currently displays far too much data in a cell and let the user select how much of the data is displayed, in the view column I put an @Left( DataField ; NoOfSelectedCharacters ) which displays the text the the users wants for each row.
Maybe not explained too well, but mail me if you want to know more.
Subject: RE: Finding the cursors position in a text area
Glad you found a workaround, but it seems to me you’re missing a bet. What if the text the user wants to show in the view isn’t at the beginning of the textarea? With the code you’ve got, it shouldn’t be difficult to figure out the start position and the end position based on what text is selected, and either store both numbers, or the selected text, in your hidden field. This is a more intuituve UI, since if the user selects characters 55 thru 80, they’re not going to be expecting to see chatracters 1 thru 26 in the view.