splattne splattne - 1 year ago 101
HTML Question

How to set the focus to the first input element in an HTML form independent from the id?

Is there a simple way to set the focus (input cursor) of a web page on the first input element (textbox, dropdownlist, ...) on loading the page without having to know the id of the element?

I would like to implement it as a common script for all my pages/forms of my web application.

Answer Source

You can also try jQuery based method:

$(document).ready(function() {
    $('form:first *:input[type!=hidden]:first').focus();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download