Javascript eventListener keydown not working EVERY time I click -


i have following code should execute each time hit f9 or f10, every other time hit it?

i have onchange event attached select box not firing every time hit f9 or f10, every other time or so. can tell alerts firing every other time hit key.

what gives?

document.addeventlistener('keydown', function(e){         if( e.keycode == '120' ){             alert("yo");             var curposition = document.getelementbyid('unpostedorders').options.selectedindex;             document.getelementbyid('unpostedorders').selectedindex =(curposition-1);             var invoice = document.getelementbyid('unpostedorders').value;             getordertomodify(invoice);         }         if( e.keycode == '121' ){             alert("gibear");             var curposition = document.getelementbyid('unpostedorders').options.selectedindex;             document.getelementbyid('unpostedorders').selectedindex =(curposition+1);             var invoice = document.getelementbyid('unpostedorders').value;             getordertomodify(invoice);         }     }, false);       

found answer, add:

document.addeventlistener('keydown', function(e){         e.stoppropagation(); // **put line in code**         e.preventdefault(); // **put line in code**         if( e.keycode == '120' ){         ... 

thank rakesh chouhan!

try

 document.addeventlistener('keydown', function(e){      e.stoppropagation(); // **put line in code**     if( e.keycode == '120' ){         alert("yo");         var curposition = document.getelementbyid('unpostedorders').options.selectedindex;         document.getelementbyid('unpostedorders').selectedindex =(curposition-1);         var invoice = document.getelementbyid('unpostedorders').value;         getordertomodify(invoice);     }     if( e.keycode == '121' ){         alert("gibear");         var curposition = document.getelementbyid('unpostedorders').options.selectedindex;         document.getelementbyid('unpostedorders').selectedindex =(curposition+1);         var invoice = document.getelementbyid('unpostedorders').value;         getordertomodify(invoice);     } }, false);      

it show alert "gibear" once every 2 times because f10 key registered browser event when press f10 first time shows alert , execute browser event , set focus on browser event operation(ie. in firefox shows menu) when again press f10 again focus browser document. when press second time focus menu document.

to check explanation when press f10 first time click page again , again press f10


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -