Thank you, John.
Would your way be more robust than what Erik presented?
Gerry
(36 years in IT, just learning JavaScript)
On 1/15/07, John Resig <[EMAIL PROTECTED]> wrote:
> 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/
>
--
Gerry Danen
Developer support:
http://dev.danen.org/
http://groups.yahoo.com/group/php_and_mysql/
Lily Register:
http://www.lilyregister.com/
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/