Results 1 to 10 of 10

Thread: How do you set focus on a specific field?

  1. #1
    Join Date
    Aug 2005
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How do you set focus on a specific field?

    I'm trying to set focus on the initial form field when the User enters the page. I'd also like to know, in case of an error, how to set focus on the error field.

    Can anyone help?

    Thanks

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    <body onload="document.forms[0].elements[0].focus();">
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2005
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks so very much! I've had open heart surgery and one of the side effects of the heart/lung machine is that parts of memory disappear - forever. This was one of those items. I really appreciate your help!!!

    Am assuming, in case of error, that one would canabalize the ONLOAD code and use the apppropriate index, right?

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Well... that's probably one of the most extreme reasons for lack of Javascript knowledge I've ever seen
    Yes indeed... the code I used was "the first element of the first form on the page." You can change them to reflect your element, or assign it an ID and access it with document.getElementById('id').
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    You can change them [the indices] to reflect your element, or assign it an ID and access it with document.getElementById('id').
    The forms and elements collections work just as well with id attributes as they do with indices and name attributes, and are better supported than the getElementById method.

    Mike

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    So, better to use the former than the latter. However, if you add a new form or element before the initial element, you will need to adjust the indices.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Aug 2005
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Attention Twey:

    You wrote:

    "Well... that's probably one of the most extreme reasons for lack of Javascript knowledge I've ever seen " is rather an unkind thing to say. It isn't lack of knowledge,sir. I've taught this stuff at the graduate level for a many years

    Talk to any cardiologist and they'll tell you the same thing: open heart surgery using a heart/lung machine selectively destroys parts of memory. Forever. No one knows why.

    Perhaps I'm just tired right now but I think an apology would not be out of place here. If I knew to whom this kind of thing should be reported, that would be my next step. It must be very nice to live in your particular world.

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I'm sorry, it wasn't intended to be insulting. Perhaps "memory" is a better word than "knowledge" in the circumstance. If you feel it should be reported, ddadmin is the one to go to.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Aug 2004
    Posts
    9,878
    Thanks
    3
    Thanked 962 Times in 951 Posts
    Blog Entries
    15

    Default

    I think this is just a misunderstanding. From how I saw it, Twey was being playful when he made that comment, with no intent to insult at all. Adding a smilie face at the end usually is a sign of that.

  10. #10
    Join Date
    Aug 2005
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    OK, then. Over and done with, I 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
  •