...

View Full Version : Disable the key "T"



Hawk
07-23-2002, 05:44 PM
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>

Hawk
07-23-2002, 06:11 PM
Very cool too!

Thanks for your help Adios.

Have a good day!

Hawk
07-23-2002, 06:14 PM
Actually, I just thought of something else.

How would you disable all keys?

Hawk
07-23-2002, 06:16 PM
I got it.

Thanks again.

function blockKeys(e)
{
var key = getKey(e);
if (!key) return true;
else return false;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum