Check if text field is active

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Check if text field is active

Post by MarK (CZ) »

Hi all!

I'm trying to find something to check that a text field is selected (focused). I need some action to be done only if the field is currently active.

Thx in advance. :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

onfocus()

i.e.

Code: Select all

<script language="Javascript">
function foc(obj)
&#123;
   alert(obj.name);
&#125;
</script>

......

<input type="text" name="whatever" onfocus="foc(this)" />
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post by MarK (CZ) »

Yeah, I could maybe use that too, thx...

But is there an element option that can tell me whether is the object active?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What are you trying to do?
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post by MarK (CZ) »

I'm just catching the onKeyPress event with a function that does some things. And I want it to do some of them only when one text field is selected. And that doesn't have to be directly after the user's focus on the element. So I need something to put in the if clause to check whether is the INPUT element active.

Code: Select all

document.onkeypress = KeyPressed;
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

<input type="text" name="whatever" onkeypress="specialstuff(this)" />
you could use the onfocus() to switch modes for the keypress handler too.. You may want to switch modes back, when you get onblur()...
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post by MarK (CZ) »

feyd wrote:

Code: Select all

<input type="text" name="whatever" onkeypress="specialstuff(this)" />
you could use the onfocus() to switch modes for the keypress handler too.. You may want to switch modes back, when you get onblur()...
Yeah, I know that, I was just wondering if there exists a property to say whether is the element active.

Thx for the replies
Post Reply