SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HTML 5 autofocus feature

    Here is a tutorial text

    HTML5 removes the need for JavaScript solutions. If a particular input should be “selected,” or focused, by default, we can now utilize the autofocus attribute.

    <input type="text" name="someInput" placeholder="Douglas Quaid" required autofocus>
    this is good. However can I use autofocus in multiple fields at the same time ?

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,175
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by windowsxp View Post
    can I use autofocus in multiple fields at the same time ?
    That would make no sense at all. Only one item can have focus at a time. So either choose which item you want focus to fall on when the page loads, or don't use the feature and let the user decide what to focus on.

  3. #3
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    Only one item can have focus at a time.
    Thanks. this helped.

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,175
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by windowsxp View Post
    Thanks. this helped.
    Out of interest, I was wondering what browsers would do if you had autofocus on more than one input. Firefox chose the first one and ignored the second. Chrome ignored the first one and put focus on the second (more what I expected).

  5. #5
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Firefox is correct. (See step 7 in http://www.whatwg.org/specs/web-apps...r-fe-autofocus )
    Simon Pieters

  6. #6
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,175
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by zcorpan View Post
    Firefox is correct. (See step 7 in http://www.whatwg.org/specs/web-apps...r-fe-autofocus )
    Ha ha, if you hadn't told me that's what step 7 meant, I'd never have guessed.


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
  •