C
Chris
Hi.
I tried to disable the backspace-key using 2 different scenarios.
One works but the other doesn't and I don't understand why the 2nd
scenario doesn't work
Scenario 1 (working scenario)
<head>
<script language="javascript" type="text/javascript">
function DisableBackspace(e) {
// for complete code, see end of mail
}
// activating the handler here
document.onkeydown = DisableBackspace;
</script>
</head>
<body> <!-- i don't specify any handler in the body section
</body>
Scenario 2
<head>
<script language="javascript" type="text/javascript">
function DisableBackspace(e) {
// for complete code, see end of mail
}
// NOT activating the handler here
// document.onkeydown = DisableBackspace;
</script>
</head>
<body onkeydown="DisableBackspace(event);"> <!-- Activating here
instead -->
</body>
but the 2nd scenario doesn't work.
why not?
thank you
Chris
Complete code:
<html>
<head>
<title></title>
<script language="javascript" type="text/javascript">
function DisableBackspace(e) {
if (!e)
e = window.event;
if (e.keyCode)
keycode = e.keyCode; // IE
else
keycode = e.which; // Firefox
if (e.keyCode == 8)
return false;
}
document.onkeydown = DisableBackspace; // uncomment
for Scenario 1
</script>
</head>
<!-- <body onkeydown="DisableBackspace(event);"> --> <!-- uncomment
for Scenario 2: -->
<body>
<!-- uncomment for Scenario 1: -->
</body>
</html>
I tried to disable the backspace-key using 2 different scenarios.
One works but the other doesn't and I don't understand why the 2nd
scenario doesn't work
Scenario 1 (working scenario)
<head>
<script language="javascript" type="text/javascript">
function DisableBackspace(e) {
// for complete code, see end of mail
}
// activating the handler here
document.onkeydown = DisableBackspace;
</script>
</head>
<body> <!-- i don't specify any handler in the body section
</body>
Scenario 2
<head>
<script language="javascript" type="text/javascript">
function DisableBackspace(e) {
// for complete code, see end of mail
}
// NOT activating the handler here
// document.onkeydown = DisableBackspace;
</script>
</head>
<body onkeydown="DisableBackspace(event);"> <!-- Activating here
instead -->
</body>
but the 2nd scenario doesn't work.
why not?
thank you
Chris
Complete code:
<html>
<head>
<title></title>
<script language="javascript" type="text/javascript">
function DisableBackspace(e) {
if (!e)
e = window.event;
if (e.keyCode)
keycode = e.keyCode; // IE
else
keycode = e.which; // Firefox
if (e.keyCode == 8)
return false;
}
document.onkeydown = DisableBackspace; // uncomment
for Scenario 1
</script>
</head>
<!-- <body onkeydown="DisableBackspace(event);"> --> <!-- uncomment
for Scenario 2: -->
<body>
<!-- uncomment for Scenario 1: -->
</body>
</html>