1

I have a js funciton executed at one textbox OnKeyUp event.

The textbox has a value by default.

If I place my cursor in the middle of the string and I add a char, the cursor moves at the end of the string.

I know that this is because the executed function recalculate and set the textbox value.

Is there a way to avoid the cursor moving at the end of the string?

Thanks

opaera
  • 11
  • 2
  • possible duplicate of [Set cursor position in html textbox](http://stackoverflow.com/questions/512528/set-cursor-position-in-html-textbox) – Gareth Apr 14 '11 at 11:38
  • Since it sounds like you're replacing the whole string with a new value, the cursor isn't *in* the new string at all. So you need to work out what position the cursor is in the old string and reset it to the same place after updating the value (see the linked question) – Gareth Apr 14 '11 at 11:40

1 Answers1

-1

Changing the value of the text in the textbox will always move the cursor to the end

Nico Westerdale
  • 2,147
  • 1
  • 24
  • 31