I’m using a regular expression to strip invalid characters out of an text input area in javascript (running in IE). I run the replace function on every keyup event. However, this makes the cursor jump to the end of the text box after each keypress, which makes inline editing impossible.
Here is it in action:
Does anyone know how to make it so the cursor does not jump to the end of the input box?
You’ll have to manually put the cursor back where you want it. For IE9, set
.selectionStartand.selectionEnd(or use.setSelectionRange(start, end)). For IE8 and earlier, use.createTextRange()and call.moveStart()on the text range.