Follow Me on Twitter
Client Support Community Server Status Contact Us Client Login
Email Hosting Website Hosting Reseller Hosting VPS Hosting Dedicated Servers

    Join our Community      Check your private messages       Profile       Search       FAQ       Memberlist       Log in


javascript gurus - text box focus state

 
Post new topic   Reply to topic    NetHosted Community Index -> Web Design
MaddogBattie Reply with quote
 Community Liason

 

 Joined: 16 Jun 2004
 Posts: 238
 Location: Cornwall

PostPosted: Thu Mar 19, 2009 12:10 am    Post subject: javascript gurus - text box focus state
 
Using javascript it is possible to give a text input box focus or to make it lose focus.

I can also detect when a text box gains focus or loses focus.

What I want to know, is it possible to know what the current focus state is without storing a flag somewhere.

I'm dynamically updating the contents of a text box every second but I also want to be to type into that box to change the value. Obviously, I need to switch off the update process when the box gets focus as otherwise the new text will be overwritten.

I'm sure this is simple but I can't find it anywhere.

Thanks in advance for any help.
Back to top
View user's profile Send private message Visit poster's website
petethegeek Reply with quote
 NetHosted Customer

 

 Joined: 14 Feb 2005
 Posts: 218
 Location: Worcester

PostPosted: Thu Mar 19, 2009 8:58 am    Post subject:
 
The focus and blur methods will give/remove focus to/from a form input element which I believe should provide you with what you need.

Code:
document.getElementById('myTextBox').focus();

_________________
"I have made this letter long, only because I lacked the time to make it short." - Blaise Pascal 1657
Back to top
View user's profile Send private message Visit poster's website
petethegeek Reply with quote
 NetHosted Customer

 

 Joined: 14 Feb 2005
 Posts: 218
 Location: Worcester

PostPosted: Thu Mar 19, 2009 9:13 pm    Post subject:
 
If you are still working on this, then the thread here  contains a couple of suggested approaches to the second - somewhat trickier - part of your question.
_________________
"I have made this letter long, only because I lacked the time to make it short." - Blaise Pascal 1657
Back to top
View user's profile Send private message Visit poster's website
boughtonp Reply with quote
 NetHosted Customer

 

 Joined: 18 Jul 2005
 Posts: 159
 Location: South Croydon

PostPosted: Sat Mar 21, 2009 2:27 pm    Post subject:
 
jQuery is the answer to all your JavaScript woes!


Or, in this case, a jQuery plugin:
http://www.softwareunity.com/jquery/JQueryMoreSelectors/


With it, you can use $j('input:focus') to get the currently focused element.

So, for example:
Code:
if ( $j('input:focus').attr('id') != 'MyAutoUpdateField' )
{
   // TODO: Perform Update.
}

_________________
Peter Boughton
Back to top
View user's profile Send private message Visit poster's website
Post new topic   Reply to topic    NetHosted Community Index -> Web Design
Page 1 of 1

User Permissions
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

 
Jump to: