set focus to ....

Discussion in 'HTML' started by Aaron, Feb 27, 2006.

  1. Aaron

    Aaron Guest

    I need to set focus to a input text field on a simple form at onLoad.

    Thanks
     
    Aaron, Feb 27, 2006
    #1
    1. Advertising

  2. Aaron wrote:
    > I need to set focus to a input text field on a simple form at onLoad.


    The form is not loaded yet.
     
    Travis Newbury, Feb 27, 2006
    #2
    1. Advertising

  3. Aaron wrote:

    > I need to set focus to a input text field on a simple form at onLoad.


    This might work:

    <body onload="document.getElementByName('textfieldname').focus()">

    Then, later in the HTML document:

    <form ...>
    <input type="text" name="textfieldname">
    </form>

    Please note that this will only work in browsers that have JavaScript
    enabled.

    --
    Kim André Akerø
    -
    (remove NOSPAM to contact me directly)
     
    =?iso-8859-1?Q?Kim_Andr=E9_Aker=F8?=, Feb 27, 2006
    #3
  4. Aaron

    Steve Pugh Guest

    "Travis Newbury" <> wrote:
    >Aaron wrote:
    >> I need to set focus to a input text field on a simple form at onLoad.


    Do you really need to? What would happen if you couldn't?

    If you have a very small page, on a fast server, with just one single
    form input (i.e. if you're the Google home page) then you can get
    away with this. Otherwise you have to consider that on a slow loading
    page the user may start typing in a form field and then when the page
    finishes loading, your script would place the focus back at the start
    of your chosen field. This would lead to the user's typing being
    screwed up.

    If you are the Google home page then look at your own source code. ;-)

    >The form is not loaded yet.


    Both the HTML spec
    <http://www.w3.org/TR/html401/interact/scripts.html#adef-onload> and
    observed behaviour in several browsers disagrees with you.

    "The onload event occurs when the user agent FINISHES loading a
    window" (my emphasis)

    Steve
    --
    "My theories appal you, my heresies outrage you,
    I never answer letters and you don't like my tie." - The Doctor

    Steve Pugh <> <http://steve.pugh.net/>
     
    Steve Pugh, Feb 27, 2006
    #4
  5. nice.guy.nige, Feb 28, 2006
    #5
  6. Aaron

    Aaron Guest

    Thanks Nige !

    "nice.guy.nige" <> wrote in message
    news:44043cf3$0$48945$...
    > While the city slept, Aaron () feverishly typed...
    >
    >> I need to set focus to a input text field on a simple form at onLoad.

    >
    > http://www.html-faq.com/htmlforms/?entryfocus
    >
    >> Thanks

    >
    > Yer welcome!
    >
    > Cheers,
    > Nige
    >
    > --
    > Nigel Moss http://www.nigenet.org.uk
    > Mail address will bounce. | Take the DOG. out!
    > "Your mother ate my dog!", "Not all of him!"
    >
    >
     
    Aaron, Feb 28, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Manav
    Replies:
    0
    Views:
    786
    Manav
    Oct 15, 2003
  2. Jason
    Replies:
    4
    Views:
    1,636
    Jason
    May 7, 2007
  3. Replies:
    2
    Views:
    344
    Thomas 'PointedEars' Lahn
    Jun 6, 2005
  4. Roger
    Replies:
    3
    Views:
    338
  5. Jeff

    manual focus vs. focus()

    Jeff, May 20, 2007, in forum: Javascript
    Replies:
    4
    Views:
    183
Loading...

Share This Page