Focus Questions

X

XSi

very simple:

is there any way I can get what field has focus in the form? I would
like to trap the "backspace" only if focus is on spesific field.
Thanks

XSi
 
M

Martin Honnen

XSi wrote:

is there any way I can get what field has focus in the form?

IE (5 and later I think, but could be 5.5 and later) has
document.activeElement
to give you the active element in the document, and basically the
element that has focus is the active element (there are subtle
differences, check MSDN).
I would
like to trap the "backspace" only if focus is on spesific field.

You could set up key event handlers on that specific field then.
 
R

RobB

XSi said:
very simple:

is there any way I can get what field has focus in the form? I would
like to trap the "backspace" only if focus is on spesific field.
Thanks

XSi

Browsers don't track keyboard focus globally (at least it isn't
exposed) so you'll need to do this yourself. Set a flag on the
"specific" ;) field:

<input...onfocus="this.hasFocus=true" onblur="this.hasFocus=false" />

....and you can test:

if (refToField.hasFocus) {....
Test keyboard mods carefully, platform issues abound...
 
R

RobB

M. Honnen wrote:

<You could set up key event handlers on that specific field then.
D'oh...that would be too simple. Never mind. :-o
 

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
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top