10

How in Jquery do I select the first blank input which is not a check box or a button. I have the following:

$(':input[value="",type!="button",type!="checkbox"]:visible:first').focus(); 

Thanks for any suggestions

brendan
  • 29,308
  • 20
  • 68
  • 109
suzi167
  • 489
  • 2
  • 8
  • 22

4 Answers4

12

Tiny bit shorter

$("input[value='']:not(:checkbox,:button):visible:first").focus();
Richard Dalton
  • 35,513
  • 6
  • 73
  • 91
  • Thanks for the answer. It worked. Btw u seem to know jquery pretty well... is there a good reference of syntax,rules,etc. I usually use the API reference from the jquery site but this particular scenario was not covered there. – suzi167 Feb 23 '11 at 13:34
  • np. I mainly use the jQuery reference online. However I also bought the jQuery 1.4 Reference Guide book and read through that just so I would have a better knowledge of the features available in jQuery. I also check this blog (http://webdevtweets.blogspot.com/) quite often, where Elijah Manor frequently posts links to good jQuery articles. – Richard Dalton Feb 23 '11 at 13:57
4
$('#formid')
  .find('input:blank:not(:checkbox,:button)')
  .filter(":visible:enabled")
  .first()
  .focus();

(During my testing, input[value=''] worked only for pre-filled empty input fields; input:blank didn't have that problem.)

Rohit Dubey
  • 1,234
  • 15
  • 15
0

UNTESTED

$('input').not('input[type!="checkbox"],input[type!="button"]');
Val
  • 17,336
  • 23
  • 95
  • 144
0
$("input[value='']:not([type='checkbox'], [type='button']):visible:first").focus()

js fiddle http://jsfiddle.net/Ft2Nh/

Jimmy
  • 9,686
  • 14
  • 59
  • 78