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

Although this doesn’t answer the question (requiring a common script), I though it might be useful for others to know that HTML5 introduces the ‘autofocus’ attribute:

<form>
  <input type="text" name="username" autofocus>
  <input type="password" name="password">
  <input type="submit" value="Login">
</form>

Dive in to HTML5 has more information.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)