This is not a one line solution, but it takes into consideration of the real first user input field (may it be <input /> or <select> tag).
You just have to tweak this a bit more and you get what you need.
P.S: I have tested this code works in FireFox, Chrome, and IE6.
function focusFirstFormField() {
try {
var selector = $("#formid");
if (selector.length >= 1 && selector[0] && selector[0].elements && selector[0].elements.length > 0) {
var elements = selector[0].elements;
var length = elements.length;
for (var i = 0; i < length; i++) {
var elem = elements[i];
var type = elem.type;
// ignore images, hidden fields, buttons, and submit-buttons
if (elem.style.display != "none" /* check for visible */ && type != "image" && type != "hidden" && type != "button" && type != "submit") {
elem.focus();
break;
}
}
}
}
catch(err) { /* ignore error if any */ }
}