javascript events - Capture down array press before cursor is moved -


if cursor positioned somewhere in input box, there way capture position using keyup before firefox moves cursor end of box?

i'm making dropdown of suggestions each input box , want suggestions moved if cursor @ end of input box. however, when try capture cursor position test this, returns end, since cursor moves end before event handler starts.

so found solution involves global variable, seems messy little thing this. declare variable

// global scope var lastcursorposition; 

then have keydown event handler on inputbox

inputbox.onkeydown = function(event) {      if(event.keycode === 40) {          lastcursorposition = cursorposition(inputbox);      } }; 

finally, in keyup event (which has other things in it), do

inputbox.onkeyup = function(event) {     if(event.keycode === 40 && lastcursorposition >= inputbox.value.length - 1) {         // show suggestions     } }; 

if has more modular solution, i'd glad hear it.

btw: if anyone's curious, i'm using cursorposition function given in this answer.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -