/ Published in: JavaScript
This code, when placed at the end of the body tag will set focus on the first visible enabled element on the screen. It considers visibility as well as all forms on-screen
Expand |
Embed | Plain Text
(function(){ var forms = document.forms || []; for(var i = 0; i < forms.length; i++){ for(var j = 0; j < forms[i].length; j++){ if(forms[i][j].type != "hidden" && forms[i][j].disabled != true && forms[i][j].style.display != 'none'){ forms[i][j].focus(); return; } } } })();
Comments
Subscribe to comments
You need to login to post a comment.

one more condition should be added to make this snip compatible with forms which contain fieldsets:
&& forms[i][j].nodeName.toLowerCase() != 'fieldset'
or something like that.
Point taken. I'll look into this soon.
James.