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
Post a Comment