Cross browser keypress event handling

Running example on JSFiddle:

[sourcecode language="javascript"]
$(document).ready(function () {
$("#TextBox1").live(‘keypress’, function (e) {
var kCode = e.keyCode || e.charCode; //cross browser check
//Mozilla and Safari define e.charCode, while IE defines e.keyCode which returns the ASCII value
if (kCode == 9) {
$("#TextBox2").focus();
}
});
});

[/sourcecode]

JavaScript Madness: Keyboard Events

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>