Jump to content

[SOLVED] focus() not working in IE


gevans

Recommended Posts

OK, here's the javascript;

 

function clearPassField(obj){
    var newInput = document.createElement('input');
    newInput.setAttribute('type','password');
    newInput.setAttribute('name',obj.getAttribute('name'));
    obj.parentNode.replaceChild(newInput,obj);
    newInput.focus();
}

 

and here's the two inputs that use it;

 

<input type="text" id="cemail" name="cemail" value="Confirm E-mail Address" onclick="clearField('Confirm E-mail Address', this.id)" onblur="checkField('Confirm E-mail Address', this.value, this.id)" /><br />
<input type="text" id="pass" name="pass" value="Password" onclick="clearPassField(this)" /><br />

 

Haven't bothere with IE6 yet, but so far IE7 and IE8 don't like it, everything works fine appart from the final focus() which works in Safari, FF2, FF3 etc...

Link to comment
https://forums.phpfreaks.com/topic/143145-solved-focus-not-working-in-ie/
Share on other sites

Ok, I've fixed it. IE is such a fussy bastard that it has to wait a second before it can focus, otherwise the element hasn't settled in properly and thinks it doesn't exist.

 

so I changed the line;

 

newInput.focus();

 

to

 

setTimeout(function() { newInput.focus(); }, 10);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.