Results 1 to 5 of 5

Thread: focus question

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Posts
    18

    focus question

    is it possible in javascript to find if a control has focus?

  2. #2
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    each control has an onfocus event which you could use to set a global variable to indicate which control fired it
    Code:
    <script>
    var gControlFocus;
    :
    function setControl(str){
     gControlFocus = str;
    }
    </script>
    :
    <input type="text" name="txt1" onfocus="setControl(this.name);">

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Posts
    18
    what if user clicks on empty place or any link, your global variable will still be containing last focused element, I need the currently focused element

  4. #4
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    Is this any better
    Code:
    document.activeElement.name
    Edit: that is probably IE specific
    Last edited by DeadEyes; Mar 19th, 2003 at 08:39 AM.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Posts
    18
    YESS! THANKS!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width