I have an input field and after a tab or enter keydown event some text is filled into the input field. How do I then make the cursor be at the end of the text that was filled?
This is the html:
<input name="author" type="text" id="author"></input>
This is the javascript:
var authorInput = document.getElementById("author");
authorInput.value = authorName;
authorInput.innerHTML = authorName;
where authorName
is a string like "example". Now after setting the innerHTML I want the cursor to be at the end of the text in the input field. How do I do this?
I prefer no jquery but am open to it if it is a much "better" solution.
Here is a jsfiddle example with an attempt at solving it, which does not work. I want the div's click event handler to make the cursor be at the end of the input text when it is done running.