Jump to content
AARRGGHHH

Does an HTML5 Control Have Focus?

Recommended Posts

I'm having a problem determining if a given control has focus.  It seems to me that:

if (form.password.focus() == true) ...

should tell me if the form's password control has focus.  But, it's returning "false" even while I'm typing into the control.  

So, what is the correct way to determine whether a control has focus? 

Thank you! 

Share this post


Link to post
Share on other sites

Thank you for the reply.

"return value" states: 

Return Value: No return value

Thus, I am assuming I cannot use my code to check for focus.   So, how do I check for focus? 

Thank you 

Share this post


Link to post
Share on other sites

The same you would for onclick, but for onfocus, when on focus set variable to true from false and if you want to attach it to that specific input use custom data- attribute and set the value to that.

Note, you will have to change it back to false, using onblur event.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...