Web Analytics Made Easy -
StatCounter Adding focus to first form field without using body onload.. - CodingForum

Announcement

Collapse
No announcement yet.

Adding focus to first form field without using body onload..

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding focus to first form field without using body onload..

    Is this possible?

  • #2
    Of course. Use window.onload .

    Code:
    window.onload = document.forms[0].elements[0].focus;

    Comment


    • #3
      So I place that in my js file. What must I add here? (which is the 1st field)

      <input type="text" maxlength="65">

      Comment


      • #4
        Nevermind, got it working with:

        function setFocus() {
        document.forms[0].elements[0].focus;
        }
        window.onload=setFocus;

        Comment


        • #5
          <form name=test1>
          <input type=text name="test">
          </form><script>
          document.forms['test1'].elements['test'].focus();</script>

          Comment


          • #6
            Originally posted by AshleyQuick
            Nevermind, got it working with:

            function setFocus() {
            document.forms[0].elements[0].focus;
            }
            window.onload=setFocus;
            function setFocus() {
            document.forms[0].elements[0].focus();
            }

            Shorter version:

            window.onload=function(){document.forms[0].elements[0].focus();}
            Glenn
            vBulletin Mods That Rock!

            Comment

            Working...
            X