I have an input box so the user can type in. I just want to disable a couple of keys not all. I know how to make an alert go off if there is a keydown. But how do I make it so when a certain key go down, it will just not do anything - not even an alert.
Thanks
adios
07-23-2002, 05:58 PM
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">
var blockedkeys = 't'; //lower-case
function getKey(e) {
return e.keyCode ? String.fromCharCode(e.keyCode).toLowerCase() :
e.which ? String.fromCharCode(e.which).toLowerCase() : null;
}
function blockKeys(e) {
var key = getKey(e);
if (!key) return true;
else return blockedkeys.indexOf(key) == -1;
}
onload = function() {document.forms[0].elements[0].focus()}
</script>
</head>
<body>
<form>
<input type="text" onkeypress="return blockKeys(event)">
</form>
</body>
</html>
Very cool too!
Thanks for your help Adios.
Have a good day!
Actually, I just thought of something else.
How would you disable all keys?
I got it.
Thanks again.
function blockKeys(e)
{
var key = getKey(e);
if (!key) return true;
else return false;
}