views:

352

answers:

0

EDIT: This turned out to be a local problem in my IE6/7/8 test setup. The problem is a non-issue on a clean default install of IE, no matter what version. You can stop reading now. :)

I'm writing a rich web application where I display a popup panel containing a simple text input field. I need to focus this text field immediately, so the user can simply start typing without having to click into the field.

I try to do this by calling the .focus() function on the input field, which works as expected in FF3.x, Safari, Chrome, and IE8.

Unfortunately this fails in IE6 and IE7. I have been unable to find any specific information on how IE6 or 7 might differ in their handling of the .focus() function. Any ideas?

I've reproduced and tested the issue in a standalone html file, here's the source:

<html>
<head>
<script type="text/javascript">
function setFocus()
{
document.getElementById('text1').focus();
}
function loseFocus()
{
document.getElementById('text1').blur();
}
</script>
</head>
<body>

<form>
<input type="text" id="text1" />
<br />
<input type="button" onclick="setFocus()" value="Set focus" />
<input type="button" onclick="loseFocus()" value="Lose focus" />
</form>

</body>
</html>