www.webdeveloper.com
Results 1 to 7 of 7

Thread: Checking if the cursor is in an input field

Hybrid View

  1. #1
    Join Date
    Jun 2010
    Posts
    3

    Checking if the cursor is in an input field

    Is there anyway I can check if the cursor is an input field? I need a function that determines if the cursor is in any input field on the page.

    Thanks!

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,670
    Code:
    ...
    <script language="JavaScript" type="text/javascript">
    <!--
    function set_inputs(){
    var inp = document.getElementsByTagName('INPUT');
    for(var i = 0; i < inp.length; i++){
    if(inp[i].type && (inp[i].type=="text")){
    inp[i].onfocus = function(){alert('The cursor is in there!');}
    }
    else{continue;}
    }
    }
    
    window.onload = set_inputs;
    //-->
    </script>
    </head>
    <body>
    ...

  3. #3
    Join Date
    Aug 2007
    Posts
    3,767
    You need the onmouseover and onmouseout (onfocus is for focusing the field, i.e. clicking in it or tabbing to it).
    Code:
    <input onmouseover="alert('Mouse is in here');" onmouseout="alert('mouse is not here');">
    If you tell us why you need to do this, and what problem you are trying to solve we can be of more help.
    Last edited by Declan1991; 06-29-2010 at 09:21 PM. Reason: Had onmousein instead of onmouseover

  4. #4
    Join Date
    Jun 2010
    Posts
    3
    Sorry should have made myself clearer.

    I am writing a firefox extension that needs to recognize when the user focuses (clicks or tabs into) on an input field. I tried the code from the first reply but for some reason it returned only empty arrays.

  5. #5
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,670
    Quote Originally Posted by gwizzlea View Post
    ... empty arrays.
    there was not nothing like "array" in your question

  6. #6
    Join Date
    Aug 2007
    Posts
    3,767
    A specific input field or all?
    That code works fine for me, Padonak's that is.

  7. #7
    Join Date
    Jun 2010
    Posts
    3
    All.. Hmm.. I'll try it again

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles