Greybox: Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus

18,654

Solution 1

It's a well known issue on IE.

You can read about it here.

The solution is to use the setTimeout() function to delay the focus() execute time.

you need to replace your line:

document.getElementById("textfield").focus();

with the following:

setTimeout(function() { document.getElementById("textfield").focus(); }, 10);

Solution 2

Just posting a quick answer to this... had to solve this tonight. Used a setTimeout to call the focus function briefly after the greybox page displays.

A little jQuery used in my version since it was already in this project but you could just as easily use window.onload()

<script type="text/javascript">
  $(document).ready(function() {
    setTimeout ( "document.getElementById('AdminID').focus(); ", 500 ); 
  });
</script>
Share:
18,654

Related videos on Youtube

Michael
Author by

Michael

Updated on April 30, 2022

Comments

  • Michael
    Michael almost 2 years

    Possible Duplicate:
    JavaScript: Visibility error in Internet Explorer when setting focus on an input element

    I have a page that loads within a greybox. I set the focus with document.getElementById("textfield").focus() - this works fine when calling the page directly.

    But when loaded in a greybox, setting the focus on the onload() event returns:

    Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus

    Calling it later works fine.

    Any ideas?

    Thanks!

  • nsilva
    nsilva over 10 years
    Thanks a lot, this was annoying the hell out of me, and was causing so many issues with IE8
  • Spiff
    Spiff over 9 years
    I've seen this error only in IE8 and older