function key pressed javascript -


i can not understand various steps of function, can explain them?

function keypress(field,e,x) {     if (!e) {         var e = window.event;     }      if (e.keycode) {         code = e.keycode;     }     else if (e.which) {         code = e.which;     }      var character = string.fromcharcode(code);     console.log("character" + character);      if (code == 13) {         box.focus();     } } 

if (!e) {     var e = window.event; } 

if e (the event variable) not defined, set window.event. makes sure have necessary data in variable e.

if (e.keycode) {     code = e.keycode; } else if (e.which) {     code = e.which; } 

browser specific tests; browser (as far know ie) uses e.wich, other browser use e.keycode. indicates key pressed user.

var character = string.fromcharcode(code); console.log("character" + character); 

converts code char.

if (code == 13) {     casella2.focus(); } 

checks if enter key pressed, if so, casella2 focused.

you can find list of different keycodes here.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -