Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE8 not allowing jQuery to give focus to textbox

I have jQuery which produces a popup window, as outlined here:

http://www.jsfiddle.net/sLjfx/4/

The problem is that the following line:

$('#txtValuation').focus();

doesn't seem to want to work in IE8. The popup will load, but the textbox doesn't have focus, where in Chrome the box does have focus.. Is there any work-around for it?

like image 784
DaveDev Avatar asked Feb 26 '23 01:02

DaveDev


1 Answers

I don't have IE8 handy, but try this: I fired up my Windows VM, and this works: http://www.jsfiddle.net/n25HE/ All I did was wrap the focus call in a function and call it 10ms after your event handler finished, like this:

setTimeout(function() {
    $('#txtValuation').focus();
}, 10);

This gives IE time to actually render the content and create the OS control for the text input. IE can't focus things before the underlying control exists.

like image 93
T.J. Crowder Avatar answered Mar 08 '23 00:03

T.J. Crowder