views:

359

answers:

2

I tried

$(":input:not(input[type=button],input[type=submit],button):visible:first")

but it doesn't find anything.

What is my mistake?

UPD: I execute this on $(document).load()

<script type="text/javascript">
$(window).load(function () {
  var aspForm  = $("form#aspnetForm");
  var firstInput = $(":input:not(input[type=button],input[type=submit],button):visible:first", aspForm);
  firstInput.focus();
});
</script>

and in the debug I can see that firstInput is empty.

UPD2: I'm in ASP.NET page running under Sharepoint.

I've found so far that for some elements it does find them (for fixed ones) and for some don't. :(

+1  A: 

The JQuery code is fine. You must execute in the ready handler not in the window load event.

<script type="text/javascript">
$(function(){
  var aspForm  = $("form#aspnetForm");
  var firstInput = $(":input:not(input[type=button],input[type=submit],button):visible:first", aspForm);
  firstInput.focus();
});
</script>

Update

I tried with the example of Karim79(thanks for the example) and it works fine: http://jsfiddle.net/2sMfU/

PeterTheNiceGuy
+1 even though I told him that 1 hour ago.
BalusC
Thanks @BalusC. I'm going to go shoot myself now. I hate myself. I could have spent the last hour not messing with working code. I could have fed my dogs, cleaned my kitchen. There are many things I could have achieved. Now all I have is pain. Goodbye, forever....And yes, I *should* have listened.
karim79
@karim: rofl. You're welcome :) Btw: I already bathed my kids, brought them in bed, fed the dogs and cats and took myself a coca cola ;)
BalusC
+3  A: 

Why not just target the ones you want (demo)?

$('form').find('input[type=text],textarea,select').filter(':visible:first')
fudgey
Checkbox? Radio? Password? Not to mention the lot of new HTML5 input types.
BalusC