Is it possible, using JavaScript or jQuery, to change the content of a text input field while the user types?
E.g. typing a + up
would change the a
to å
, while keeping the input cursor at the same position.
Is it possible, using JavaScript or jQuery, to change the content of a text input field while the user types?
E.g. typing a + up
would change the a
to å
, while keeping the input cursor at the same position.
Yes, change it on the fly and keep
selectionStart
andselectionEnd
at the previous position: http://jsfiddle.net/pimvdb/p2jL3/3/.selectionStart
andselectionEnd
represent the selection bounds, and are equal to each other when there is no selection, in which case they represent the cursor position.Edit: Decided to make a jQuery plugin of it, since it may come in handy later and it's easy to implement anywhere that way.
I once had to do a similar thing. I think this is much simpler. Modify it to meet your needs: