Focus on the first enabled form field

Asked

Viewed 720 times

3

This way I activate the Focus in the first field of the form that is not hidden:

$('form:first *:input[type!=hidden]:first').focus();

As active the focus in the first field of the form which is not hidden and also not a disabled field (disabled)?

  • If the answer has been useful mark it as correct, so we help other possible users.

1 answer

5


With jQuery

$('form:first *:input[disabled != disabled], [type != hidden] :first').focus();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<form>
  <input type="hidden">
  <input type="text" disabled>
  <input type="text">
</form>

Or

Use the attribute autofocus of HTML 5.

<input type="text" autofocus>
<input type="text">

Browser other questions tagged

You are not signed in. Login or sign up in order to post.