Results 1 to 5 of 5

Thread: Help with Set focus anyone?

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

    Default Help with Set focus anyone?

    I already have code that will set focus on a FORM statement from Twey - ONLOAD="document.forms[0].elements[0].focus()" - but between the BODY statement and where I want the focus, there are two separate tables and a .GIF. This makes the set focus fail every time.

    Anyone have any suggestions?

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

    Default

    Give the element an id.
    Code:
    <input type="whatever" id="firstfocus"/>
    ... then use
    Code:
    onload="document.getElementById('firstfocus').focus();"
    However, the only thing that ought to mess up that script is if there is another form before that one, or if the first element can't receive focus (E.G. input type="hidden").
    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 but still have a problem

    Thanks for the help, Twey. I've not run across this one before, that I know of.

    The screeen does indeed put the focus where I want it, but it also puts the ONLOAD code on the screen as well. Very strange to me.

    It appears you can't' slap an image in here but here's the code line:
    <BODY SCROLL="no" CLASS="Margin4pct WhiteLeather" ONLOAD="document.getElementById('addressName').focus();">

    the actual focus field looks like this:
    <DIV CLASS="SectionTitle">
    NAME AND ADDRESS
    </DIV>
    <LABEL FOR="addressName" CLASS="appointmentTD">
    onload="document.getElementById('firstfocus').focus();"
    Name:
    <INPUT CLASS="appointmentInput" TYPE="text" ID="addressName"
    TABINDEX="1" SIZE="18" MAXLENGTH="60" NAME="addressName"
    ONBLUR="changeback(addressName)"
    ONFOCUS="highlight(addressName)"
    ONKEYPRESS="return handleEnter(this,event)"> </LABEL>

    While it does set focus on thie field, the onload code appears as well. It preceeds the input field addressName. Any suggestions?

    Thanks for al of your help, Twey. It is greatly appreciated! Bits and pieces of memory are returning but not all. The Medico's say I may never get everything back. Very frustrating for me.

    jim

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

    Default

    Code:
    <LABEL FOR="addressName" CLASS="appointmentTD">
    onload="document.getElementById('firstfocus').focus();"
    I'm not surprised You've forgotten to remove that code, just closing the tag before it so the browser sees it as text. Remove the red text.
    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
    Aug 2005
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Right as rain just like always. Thanks!

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
  •