Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

javascript

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!

like image 867
Michael Avatar asked Aug 10 '10 18:08

Michael


2 Answers

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);
like image 135
Dor Cohen Avatar answered Nov 01 '22 22:11

Dor Cohen


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>
like image 42
Autosoft Avatar answered Nov 01 '22 20:11

Autosoft