I'd try something like this:
$(function() {
var field = $("#second_field_to_enter")[0];
if ( field ) {
field.focus();
} else {
$("#first_field_to_enter")[0].focus();
}
});
That might get you at your desired goal.
--John
On 1/15/07, Gerry Danen <[EMAIL PROTECTED]> wrote:
> In this piece of code (common to a number of pages) I want to set
> focus to a second input field if there is one.
>
> $(function() {
> $("#first_field_to_enter")[0].focus();
> $("#second_field_to_enter")[0].focus();
> });
>
> If the second input field is present, focus is on the second field. If
> not present, focus goes to the first field. All good, except that an
> error is generated in FF2 error console when the second field is not
> present.
>
> See http://test.danen.org/secure/register.htm and
> http://test.danen.org/secure/ for an example of each case.
>
> html is:
> <input id="first_field_to_enter" type="text" name="form_id" size="26">
> <input id="second_field_to_enter" type=text name=rf_namef size="50"
> maxlength="50">
>
> Both fields are in different <form>s.
>
> Is there a way to test for the presence of the second field?
>
> Please excuse my ignorance if the answer is obvious, but I'm a
> JavaScript newbie, and I just found jQuery today. John Resig and the
> jQuery team, hats off to your excellent work.
>
> Thanks for your help.
>
> Gerry
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/