I would like to place the cursor in an input field after a specific link is clicked. I’m using this for a small search engine.
Imagine an input field: []. Then some links which is adding a string like: Denmark, England etc. to the input field.
Now I need the cursor to be placed like this: “Denmark, [here]”.
Is this possible?
* UPDATE *
I’m using this code right now to replace the text, how would you add the “position cursor”-trick with this?
$('#denmark').click(function(){
$('#searchBoxBig').val('Denmark, ');
});
You can set where the cursor is in an input box with the
selectionStartandselectionEndproperties. If you don’t want any text to be selected, just make them equal to each other.Here’s how you might do it: