SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    USA
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding focus to first form field without using onload in the body tag

    Is this possible? I'm sure it's something simple with window.onload I'm just brain dead today (and most days)

    Here's the 1st field I'm using:

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

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Try this:
    Code:
    function setFocus() {
      document.forms[0].elements[0].focus;
    }
    window.onload=setFocus;

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    USA
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool, works great!

    Thankie

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vgarcia...
    Code:
    onload = function()
    {
         document.forms[0].elements[0].focus();
    }
    Calling it. Also: why create a new global ('setFocus')? Anonymity is a virtue.
    ::: certified wild guess :::


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •