Disable the <Esc> Key ??

M

Mel Smith

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.
 
N

nick

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.
 
N

nick

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.
 
N

nick

"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.
 
R

RobG

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 ??

It would be more useful to say what behaviour you are trying to
modify, rather than simply asking to disable the key.

You can't disable the key using javascript code running in a browser,
however you may be able to prevent particular default responses to its
being pressed in some circumstances. It all depends on the browser and
behaviour as different browsers do different things in different
circumstances in response to varouis key presses.

If the issue is related to modifying user behaviour, you may be better
off teaching them different usage patterns than trying to modify the
browser UI.
 
M

Mel Smith

Nick, Stefan, and Rob:

Thank you all for the comments and suggestions. My users (unknown to me)
will probably have an IE browser (probably 6/7/8 for now), with perhaps a
few having a different/better browser (I have most of the current browsers
on my dev machine, but my stuff *must* still work on IE6 and better)
It would be more useful to say what behaviour you are trying to
modify, rather than simply asking to disable the key.

In my real app I have approx 72 single-char (usually digit) input text
fields.

When the user inputs a (say) digit, there are several operations I have
to carry out (totalling, modifying, etc, etc other fields).

I have to be prepared for my users making mistakes, and allowing them
(and controlling them) in the usage of <Backspace>,<Tab>, <Delete>, <Esc>,
etc, etc.

I kow what I *want* to happen when a user presses a particular key, and
can (mostly) control my JS response to the key.

I have onfocus, onblur, and onkeyup JS functions active for all my
fields. The onfocus and onblur control background color, and the onkeyup
function should get all keys from the user, and act on them appropriately.

*However*, the <Esc> input from IE puzzles me:

On Focus, the mouse pointer shows as a vertical in *front* of the
single digit, but with the following onkeyup event, it appears in the same
field but *after* the single digit -- with the digit still remaining in the
field. *But* apparently the onblur event is called after the second press
You can't disable the key using javascript code running in a browser,
however you may be able to prevent particular default responses to its
being pressed in some circumstances. It all depends on the browser and
behaviour as different browsers do different things in different
circumstances in response to varouis key presses.

My problem is the way IE7 treats the various keys in my JS 'onkeyup'
function. Some keys modify the field *before* my onkeyup is activated, some
don't do anything, and the rest I haven't determined yet.

But, so far, it is the operation of two sequential <Esc> key inputs in
the same field that blows me away.

(It may be that the onblur event occurs after the *second* <Esc> input
on a specific field. I'll have to investigate this later today)

If the issue is related to modifying user behaviour, you may be better
off teaching them different usage patterns than trying to modify the
browser UI.

I won't even know where or who my users are until I get this app
going. So, there's minimum I'll be able to modify their behaviour :((

What I don't want is the user to feel frustrated when entering these
70-odd input fields. He/She will never return if I demand perfection.

Thank for all your comments !

-Mel Smith
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top