From: Mel Smith on
Hi:

On a single-digit Input Text field, I would like to disable the action
of the <Esc> Key.

How do I do this please ??

Thanks.
--
Mel Smith


From: nick on
On Apr 12, 9:50 pm, "Mel Smith" <med_cutout_syn...(a)aol.com> wrote:
> Hi:
>
>     On a single-digit Input Text field, I would like to disable the action
> of the <Esc> Key.
>
> How do I do this please ??
>
> Thanks.

Create a keypress / keydown event handler on the document and return
false if the keycode was 9. Search for javascript key event handling.
From: nick on
On Apr 12, 9:59 pm, nick <nick...(a)fastmail.fm> wrote:
> On Apr 12, 9:50 pm, "Mel Smith" <med_cutout_syn...(a)aol.com> wrote:
> >     On a single-digit Input Text field...
>
> Create a keypress / keydown event handler on the document and return
> false if the keycode was 9. Search for javascript key event handling.

Sorry, create the event handler on the input field, not the document.
I think that will work, if not you can create it on the document and
check that the active element was the text field before returning
false.
From: Stefan Weiss on
On 13/04/10 04:01, nick wrote:
> On Apr 12, 9:59 pm, nick <nick...(a)fastmail.fm> wrote:
>> On Apr 12, 9:50 pm, "Mel Smith" <med_cutout_syn...(a)aol.com> wrote:
>> > On a single-digit Input Text field...
>>
>> Create a keypress / keydown event handler on the document and return
>> false if the keycode was 9. Search for javascript key event handling.
>
> Sorry, create the event handler on the input field, not the document.
> I think that will work, if not you can create it on the document and
> check that the active element was the text field before returning
> false.

"if the keycode was 9"? Escape should be 27, but maybe your browser/OS
is different.

Assuming the "single-digit input text field" the OP mentioned is an
ordinary text input field, the behavior when the escape key is pressed
is not consistent across browsers. Different browsers handle it in
different ways: Firefox does nothing, Opera removes the focus from the
field, and MSIE removes the entered text but keeps the field focused.
Not knowing which behavior the OP wants to prevent makes it difficult to
offer a solution.

This may help as a starting point:

myInput.onkeydown = function (evt) {
evt = evt || window.event;
if (evt && evt.keyCode == 27) {
return false;
}
};


--
stefan
From: nick on
On Apr 12, 10:45 pm, Stefan Weiss <krewech...(a)gmail.com> wrote:
>
> "if the keycode was 9"? Escape should be 27, but maybe your browser/OS
> is different.

Whoops, 27 it is. I had just been playing with a utility called
xmacrorec2 that was reporting my <esc> keypresses as keycode 9,
apparently incorrectly, and I didn't bother to double check. Sorry
about that.