IE Focus Problem
I making an application that required to focus() on text input on a form. All the form is using AJAX. Usually u just need this command to make it work using Jquery:
$(“#search_code”).focus();
But i think IE 7 has a problem focusing on created-on-the-fly-DOM text input. It won’t focus. Firefox does this splendidly without any problem. So i think this may resolve the problem
$(“#search_code”).blur().focus();
And it doesn’t. I try to googling and found some site to try select first than focus. So i type this code :
$(“#search_code”).select().focus();
It work on the first DOM, when i remove the field and recreated it, it won’t focus anymore…
After 3 days stuck on this error. I decided on temporarily fixed this with stupid workaround
function ieFocus(el) { // Damn IE for(a = 0 ; a < 10 ; a++) { el.blur(); el.focus(); }}
I’m trying to find a proper solution to this problem. Have anyone have a same problem before? Please reply ^^
Thanks in advance.
The original post is old but if it helps someone. Here’s the code:
function getfocus(control_id)
{
obj = document.getElementById(control_id);
if (obj)
{
if (obj.type==’text’)
{
obj.blur();
obj.select();
}
obj.focus();
}
}
setTimeout( getfocus, 100 );