Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
"Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus."


This JavaScript error is shown when I try to focusing an HTML input dynamically from code... the control is HTML input and it is neither invisible nor disabled.

What could be the reason of the error and what is the solution for it?
Posted
Updated 24-Aug-10 8:05am
v3

Check whether the parent element of the html input control is disabled or not. If your input element is withing a div that is disabled then you cannot focus to that input control.
 
Share this answer
 
Put a check like this and see if the reasons provided are really true:
JavaScript
if(element.style.visibility=="hidden" || element.style.display=="none" || element.disabled==true) {
    //do something because it can't accept focus()
} else {
    element.focus();
}


If you still get the error, then use a 'try-catch' block and verify the same.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900