JavaScript insert at caret function