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!
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>
...
use [code]YOUR CODE GOES HERE [/code] or burn in Hell
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 08:21 PM .
Reason: Had onmousein instead of onmouseover
Great wit and madness are near allied, and fine a line their bounds divide.
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.
A specific input field or all?
That code works fine for me, Padonak's that is.
Great wit and madness are near allied, and fine a line their bounds divide.
All.. Hmm.. I'll try it again
Originally Posted by
gwizzlea
... empty arrays.
there was not nothing like "array" in your question
use [code]YOUR CODE GOES HERE [/code] or burn in Hell
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
Forum Rules
Bookmarks