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!
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);
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With