[pmwiki-users] can the cursor be positioned on forms?

Patrick R. Michaud pmichaud at pobox.com
Thu Mar 23 18:48:33 CST 2006

On Fri, Mar 24, 2006 at 12:32:32AM +0000, ljb wrote:
> pmichaud at pobox.com wrote:
> >...
> > I might see if I can find a generic javascript snippet that will
> > always focus the first field in the form (instead of an explicitly
> > named field as it does now).
> Maybe this:
>    document.forms[0].elements[0].focus();
> Unless there might be hidden form fields at the top of the form. If so,
> maybe this:
>   for (i=0; i<document.forms[0].elements.length; i++)
>     if (document.forms[0].elements[i].type != 'hidden') {
>       document.forms[0].elements[i].focus();
>       break;
>     }
> All this assumes there is only one form on the page. (Not true with my
> site's skin, which has a search form in the header.)

There's almost always more than one form on the page, and
there are hidden elements before the first visible one.
But doing the loop or something like it will probably work.


More information about the pmwiki-users mailing list