Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Why can't Jimmy focus()?

    I've got an older style frameset (3 frame within). Its a user browse/select set. Top frame is controls, middle is headings & sort control, bottom is the scrollable browse data.

    This needs a performance solution since it works fine when the browse data is low volume (or the network is blazing fast).

    The prob: Once the set is fully loaded the cursor is placed in a text box in the control frame allowing the user to be able to type a search term without having to click in the textbox.

    Problem is the cursor doesn't stick in the bottom frame after _all_ that data loads I tried:
    Code:
     window.parent.MCABrowseControl.document.getElementById('txtQuickFind').focus()
     alert("after")
    no errors of any kind and for a split second the cursor is visible -- and then is gone (the focus appears to revert to the bottom frames first input (a radio button)

    I messed with onreadystatechange but couldn't get my fx to fire when the state became "complete". It only fired once when "loading"

    Any methods/properties I can use to solve the issue of _waiting_ for all frames to finish before setting the focus(), and have it stay there?

    thanks

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,200
    Thanks
    75
    Thanked 4,342 Times in 4,308 Posts
    Sure.

    Code:
    <script>
    var loaded = 0;
    function frameLoaded(whichFrame)
    {
        loaded |= whichFrame;
        if ( loaded == 7 ) 
        {
            document.getElementById("someFrameId").document.getElementById('txtQuickFind').focus()
        }
    }
    </script>
    <frameset>
        ...
    </frameset>
    Then, in the code for *each* frame, do
    Code:
    <body onload="parent.frameLoaded(1);">
    
    <body onload="parent.frameLoaded(2);">
    
    <body onload="parent.frameLoaded(4);">
    (That is, use 1,2,4 as the arguments to frameLoaded.)

    You see it? As each frame loads, it sets a bit in the frameset's loaded variable.

    Only when all 3 have called will the "OR" of the bit values be 7 and only then will you move the focus.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    rokosz (09-14-2011)

  • #3
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Wow, that's so much more elegant than what my brute force idea:

    I was starting an effort to load the src parameter for the 2nd, 3rd frames as each of the preceding frames had completed via code.

    Thanks! I'd thought there had to be a "frameset" level solution and you clued me in. Jimmy likes to byte.

  • #4
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Well, it seems my exuberance has been damped. During installation of the above logic it worked solidly -- as long as there was an alert() (put there for testing) immediately before the .focus() -- or really anywhere in frameLoaded().

    Remove the alert() and the .focus will fail anywhere from 10% to 99% of the time (seems to depend on data load -- the 3rd frame can have anywhere from 1 to 100 radio buttons)

    so now I'm trying to figure out what processing occurs after all the <body onload> events have fired that would usurp the focus() I just set.

    I've been grasping at the following straws (none of which made a diff)
    1) ensure caching is on (or off)
    2) is self.location.hash=... the culprit
    3) is debug mode a culprit (my environment is whack right now re: debug mode). Currently I'm trying to turn it off w/o success (the aspclientdebug=1 cookied will not go away)
    4) theres no activex, ajax or coms involved -- straight vbscript,javascript and html.

    Anybody out there have an idea of what could be firing after the frames are fully loaded and I've set the focus()?

    thanks to all who may help, B

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,200
    Thanks
    75
    Thanked 4,342 Times in 4,308 Posts
    Well, here's a hacky idea.
    Code:
    <script>
    var loaded = 0;
    function frameLoaded(whichFrame)
    {
        loaded |= whichFrame;
        if ( loaded == 7 ) 
        {
            focusIt();
            setTimeout( focusIt, 250 );
        }
    }
    function focusIt( )
    {
        document.getElementById("someFrameId").document.getElementById('txtQuickFind').focus()
    }
    </script>
    That is, do it once, and then do it again a quarter second later. Should be too fast for humans to worry about.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you OPedant - that did the trick. A simple enough hack. Though the curious cat in me still wants to know where the or what the lag is in that page after all the <body>s are loaded...

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,200
    Thanks
    75
    Thanked 4,342 Times in 4,308 Posts
    Me, too. But without seeing *all* your code, I can't guess.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

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