Feedback on: irt.org FAQ Knowledge Base Q1345
Worth:
Worth reading
Comments:
I tried this function but it still never worked. Actually I have this backspace key problem on the dropdown (select) box. Is there a way to cancel the key differently on this form element?
Technical:
Not technical enough
Comments:
Works on IE5.0 and not on IE4.0
Worth:
Very worth reading
Length:
Just right
Technical:
Just right
Comments:
This trick didn't work for me, but this code seems to do the trick:
if(event && event.keyCode == 8)
event.keyCode = 0;
Technical:
Just right
Comments:
Gray's version works for both IE4 and IE5. But we need the backspace to work for text and textareas, the function should be modified to:
if (window.event && window.event.srcElement.tagName !='INPUT' &&
window.event.srcElement.tagName !='TEXTAREA' && window.event.keyCode == 8) {
//Cancel the backspace
window.event.keyCode = 0;
}
Worth:
Length:
Technical:
Comments:
<script language="JavaScript"><!--
document.onkeydown = mykeyhandler;
function mykeyhandler() {
if (window.event && window.event.keyCode == 8) {
// try to cancel the backspace
window.event.cancelBubble = true;
window.event.returnValue = false;
return false;
}
}
//--></script>
Here in the above script just check out for the event's source element's tag name.If cursor is not focussed in any text box you will find out the tag name 'body',other wise you will get 'input'.
It can be done in this way
function mykeyhandler() {
if (window.event && window.event.keyCode == 8 && window.event..srcElement.tagName == "BODY") {
// try to cancel the backspace
window.event.cancelBubble = true;
window.event.returnValue = false;
return false;
}
}