Entry
How can i prevent a user to press ESC in a text box in order to avoid that text inside the text box disappeared?
Dec 3rd, 2001 03:42
Dan, Meropi Petraki,
Just filter out ESC in key down event.
The ASCII code for ESC is 27, so in key down event
check if keyCode has this value. If yes, make
event.returnValue = false.
Example:
<html>
<head>
<script language="javascript">
function onKeyDown() {
if (event.keyCode == 27) {
event.returnValue = false;
}
} // onKeyDown
</script>
</head>
<body>
<form name="aForm">
<input type="text" name="aText" onkeydown = "onKeyDown()">
</form>
</body
</html>