views:

470

answers:

1

I'm trying to set the focus on a text input element using

document.getElementById( 'id' ).focus()

This works in Firefox 3, but does not work in Internet Explorer 8.

What is the correct way to set focus on an HTML element in Internet Explorer?

+5  A: 

Are you sure there isn't another problem with your code? I don't have an IE8 to test with, but this self-contained example works perfectly in IE7 - perhaps you could try it in IE8?

<html><body>
<form><input type='text' id='bim'></form>
<script>document.getElementById('bim').focus()</script>
</body></html>
RichieHindle
Yep, you're absolutely correct. I had an unrelated bug in my code that prevented it from working in IE.
Mike Ottum