JavaScript and client side scripting.
Moderator: General Moderators
MarK (CZ)
Forum Contributor
Posts: 239 Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:
Post
by MarK (CZ) » Sun Jul 04, 2004 2:37 pm
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jul 04, 2004 2:48 pm
onfocus()
i.e.
Code: Select all
<script language="Javascript">
function foc(obj)
{
alert(obj.name);
}
</script>
......
<input type="text" name="whatever" onfocus="foc(this)" />
MarK (CZ)
Forum Contributor
Posts: 239 Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:
Post
by MarK (CZ) » Sun Jul 04, 2004 2:51 pm
Yeah, I could maybe use that too, thx...
But is there an element option that can tell me whether is the object active?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jul 04, 2004 3:11 pm
What are you trying to do?
MarK (CZ)
Forum Contributor
Posts: 239 Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:
Post
by MarK (CZ) » Sun Jul 04, 2004 3:20 pm
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jul 04, 2004 3:29 pm
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()...
MarK (CZ)
Forum Contributor
Posts: 239 Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:
Post
by MarK (CZ) » Sun Jul 04, 2004 4:59 pm
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