Focus Questions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • XSi

    #1

    Focus Questions

    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

  • Martin Honnen

    #2
    Re: Focus Questions



    XSi wrote:

    [color=blue]
    > is there any way I can get what field has focus in the form?[/color]

    IE (5 and later I think, but could be 5.5 and later) has
    document.active Element
    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).
    [color=blue]
    > I would
    > like to trap the "backspace" only if focus is on spesific field.[/color]

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


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • RobB

      #3
      Re: Focus Questions

      XSi wrote:[color=blue]
      > 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[/color]

      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...onfocu s="this.hasFocu s=true" onblur="this.ha sFocus=false" />

      ....and you can test:

      if (refToField.has Focus) {....
      Test keyboard mods carefully, platform issues abound...

      Comment

      • RobB

        #4
        Re: Focus Questions

        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

        Comment

        Working...