Autofocus form with prototype

How to make a web page autofocus using prototype

1. include js on header:

hasClassApplied = function(element, classname
  {
    if (element != undefined && (Element.classNames(element) != undefined || Element.classNames(element) != null))
    {return Element.classNames(element).include(classname);}
    return false;
  }

 focusFirstPageInput = function(excludeFormClassname)
  {
    for (i = 0; i < document.forms.length; i++)
    {
      if (!hasClassApplied(document.forms[i], excludeFormClassname))
      {
        focusFirstFormInput(document.forms[i]);  
        return;
      }
    }
  }

 focusFirstFormInput = function(form)
  {
    for (i = 0; i < form.length; i++)
    {
      if (form[i].type != "hidden" && form[i].type != "submit" && form[i].type != "button")
      {
        if (!form[i].disabled)
        {
          Field.activate(form[i]);
          return;
        }
      }
    }  

2. on the body tag, include on onload:

<body onload="focusFirstPageInput('')></body>  

0 comments:

Post a Comment