Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to set focus in Firefox/Opera

Setting focus on a form element using JavaScript is usually very straight forward. I cannot get this working in Firefox 12.0 or Opera 11.

Works in other browsers (Chrome, IE etc) and Firefox 3.6.

Simple HTML:

<form action="">
    <input type="radio" id="focusID1" name="sex" value="male" /> Male<br />
    <input type="radio" id="focusID2" name="sex" value="female" /> Female<br />
</form>

​Simple Javascript:

var elem = document.getElementById("focusID2");
if (elem != null) {
   elem.focus();
}

Try this for yourself at http://jsfiddle.net/4Ddtv/. ​

like image 518
j.davies Avatar asked Nov 03 '22 23:11

j.davies


1 Answers

Firefox was working as expected. Issue was with jsfiddle focus and firefox not highlighting the focused element.

This is not an issue.. User error!

like image 193
j.davies Avatar answered Nov 12 '22 18:11

j.davies