PDA

View Full Version : How to check if field is focused


nms
12-13-2002, 08:20 PM
I have a script which acts on the cursor keys.
When you hit left or right cursor, you browse thru the database.

This may not occur, if you are in the search-box.

How to check if the cursor is in the search-text-input?

if (document.myform.search.focus)

???
How?

Erik

chrismiceli
12-13-2002, 10:27 PM
why not just give it focus?

cheesebagpipe
12-13-2002, 11:34 PM
.focus() is a method (function) - not a data property; you can't 'check' for it. You can use the onfocus handler of a field to run JS that will do something if a field has focus, however:

<input name="search"
onfocus="this.hasfocus=true"
onblur="this.hasfocus=false">

Then just test your new property:

if (document.myform.search.hasfocus) {......

Might be a better way to handle this, but can't tell w/o more info.

nms
12-14-2002, 06:35 AM
Seems logic to me.
I have now done something similair only more difficult.
I set and unset a hidden fields value.
But this seems more logical.

Thanks!