Does anyone have trouble finding a cross-browser way to determine what keystroke is pressed?
To catch a keypress in a input box and determining on if its a TAB key or ENTER key and then run some code, here is the script. This works fine for IE and firefox.
var nextID = null;
function kH(e) {
var code;
if (!e) var e = window.event
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
if((code==13)||(code==9))
{
document.getElementById(nextID).focus();
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
return false;
}
else
{
return true;
}
}
function catchtabenter (evt, cNextID)
{
nextID = cNextID;
return kH(evt);
}
/>
No comments:
Post a Comment