There are buttons of the "virtual keyboard", with the help of which the characters of another language are entered into the text fields, which the "average" user does not have on the keyboard.

Now it works as follows: when the text field loses focus, its id is stored in a variable, that is, the id of the last input in which the cursor was located in this variable. If the user now clicks on the buttons of the virtual keyboard, then the corresponding character is added to the end of this text field. It's simple...

But, let's say, the character needs to be added not to the end of the line in the field, but to the middle, i.e. the cursor in this field stood in the middle of the word. You can remember by focusout, along with the id field, in which position the cursor was in the field, but how to determine in which position in the text in the field is the cursor? Something I can not figure out, tell me, pliz :)

  • bump I'm looking for an answer myself. - knes
  • it seems that there are no standard methods to determine this. From the ideas that come to mind: by focusout, call presskey programmatically and add a special character to the text (probably, some invisible is desirable ... what options are there?), After determining the position of this special character and remember and delete the special character. - xhr

1 answer 1

See an example here , like a small amount of code.