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
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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.