faqts : Computers : Programming : Languages : JavaScript : Forms : TextAreas/TextFields

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

16 of 19 people (84%) answered Yes
Recently 8 of 10 people (80%) answered Yes

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>