AARRGGHHH Posted April 11, 2018 Share Posted April 11, 2018 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! Link to comment Share on other sites More sharing options...
dsonesuk Posted April 11, 2018 Share Posted April 11, 2018 https://www.w3schools.com/jsref/met_html_focus.asp The bit where it says returned value. You can only change a variable value within a function that is called once an onfocus event takes place. Link to comment Share on other sites More sharing options...
AARRGGHHH Posted April 11, 2018 Author Share Posted April 11, 2018 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 Link to comment Share on other sites More sharing options...
dsonesuk Posted April 11, 2018 Share Posted April 11, 2018 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now