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
  • 28,436
  • 19
  • 65
  • 106
suzi167
  • 489
  • 2
  • 8
  • 22

4 Answers4

12

Tiny bit shorter

$("input[value='']:not(:checkbox,:button):visible:first").focus();
Richard Dalton
  • 34,863
  • 6
  • 72
  • 90
  • 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,136
  • 14
  • 14
0

UNTESTED

$('input').not('input[type!="checkbox"],input[type!="button"]');
Val
  • 16,830
  • 22
  • 94
  • 144
0
$("input[value='']:not([type='checkbox'], [type='button']):visible:first").focus()

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

Jimmy
  • 9,546
  • 13
  • 56
  • 77