View Full Version : Keystroke 35 question for an input field

Oct 19th, 2013, 11:30 PM
Hi All,

Generally take it as read that we can detect a keystroke number and for this question the 'End' key press on a keyboard is 35.

Also using normal javascript you can set up instruction to say if key 35 pressed do this.

However, how do you get a javascript to actually do the action of jumping to the end of a line of text in an input field where all the text in the field is not possible to show.

I know you can bring the input field into focus with code, but not sure how you then say do a 35 keystroke dynamically as if someone had actually pressed the key?


Logic Ali
Oct 20th, 2013, 12:44 AM
textBox.scrollTop = textBox.scrollHeight;

Oct 28th, 2013, 01:05 PM
Hi All,

Just wanted to show with the code below what I was trying to do when I wrote my original post.

The idea was related to the browse input fields when you select a file. The browse display field shows the address to the file but shows the start and unless you scroll to the end of the display you don't actually know what file name is there.

The code below makes the cursor in the display jump to end so you can see the file name. Not sure if it is of use to anyone, just another one of my what if and can you do this or that thoughts.

function moveCursorToEnd(el) {
if (typeof el.selectionStart == "number") {
el.selectionStart = el.selectionEnd = el.value.length;
} else if (typeof el.createTextRange != "undefined") {
var range = el.createTextRange();

<input type="file" id="el" style="width:300px" onmouseover="moveCursorToEnd(el)">