tags:

views:

149

answers:

2

I'm using this line of code:

$(":text:visible:enabled:first").focus();

It works in Firefox but not in Chrome, IE8, IE7, or Safari. I would ideally like to place the cursor in a text field at a form so that one may just starting typing in the field without having to navigate to it with a mouse.

A: 

Try setting the text field id and use that. The text field would look like:

<input type="text" id="mytextfield" />

And the script would look like this:

$(function(){
    // On Page Load
    $('#mytextfield').focus();
});
Matt Williamson
+1  A: 

That should work... Try debugging using any JS debugger. I bet you're having some JS error preventing the rest of the code to continue in other browsers.

Also, old school debugging - try this line right before your focus() one:

alert( $(":text:visible:enabled:first").length );

That should alert 1. If you don't get any alert box, then that line is not being reached at all.

Seb