Focus on the first field enabled in the form

3

In this way I activate the focus in the first field of the form that is not hidden :

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

How do I activate focus in the first field of the form that is not hidden and is not also a disabled field ( disabled )?

    
asked by anonymous 20.01.2017 / 19:58

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><inputtype="hidden">
  <input type="text" disabled>
  <input type="text">
</form>

Or

  

Use the autofocus attribute of HTML 5 .

<input type="text" autofocus>
<input type="text">
    
20.01.2017 / 19:59