Refresh Page - Unless Condition

Discussion in 'Javascript' started by lucanos@gmail.com, Jul 26, 2005.

  1. Guest

    Hey Guys,

    Hoping that you can help me, as I have been scratching my head and
    getting nothing but dandruff...

    SITUATION
    ---------
    I have a webpage which users will be viewing, which has forms which can
    be hidden or displayed at the user's choice. The problem is that they
    want the page to refresh every X seconds, but if it refreshes when a
    form is displayed, then the form loses the entered data and disappears
    as the screen is redrawn, meaning the user has to write it all up
    again.

    MISSION
    -------
    I want to create a JavaScript refresh function, which will only refresh
    the page if a certain condition is met. The condition will be a
    variable which will count the number of forms currently being
    displayed. If the variable ('openForms') is 0, then the refresh should
    be executed.

    ATTEMPTS THUSFAR
    ----------------
    function refreshCounter() {
    Id = setTimeout( refreshWindow() , 100000 );
    }
    function refreshWindow() {
    if ( openForms==0 ) {
    // No Windows Open - Reloading
    window.location.reload(true);
    } else {
    // Windows Open - NO Reload
    }
    }

    RESULT THUSFAR
    --------------
    The page was constantly trying to reload the second it opened - causing
    a loop which only stopped when I commented out the second line of
    "refreshCounter()".

    Any suggestions, or assistance would be appreciated.
    Am I doing this the easiest possible way? Or is there a better option?

    Thanks
    Luke
     
    , Jul 26, 2005
    #1
    1. Advertising

  2. Jedi Fans Guest

    wrote:
    > Hey Guys,
    >
    > Hoping that you can help me, as I have been scratching my head and
    > getting nothing but dandruff...
    >
    > SITUATION
    > ---------
    > I have a webpage which users will be viewing, which has forms which can
    > be hidden or displayed at the user's choice. The problem is that they
    > want the page to refresh every X seconds, but if it refreshes when a
    > form is displayed, then the form loses the entered data and disappears
    > as the screen is redrawn, meaning the user has to write it all up
    > again.
    >
    > MISSION
    > -------
    > I want to create a JavaScript refresh function, which will only refresh
    > the page if a certain condition is met. The condition will be a
    > variable which will count the number of forms currently being
    > displayed. If the variable ('openForms') is 0, then the refresh should
    > be executed.
    >
    > ATTEMPTS THUSFAR
    > ----------------
    > function refreshCounter() {
    > Id = setTimeout( refreshWindow() , 100000 );
    > }

    <SNIP>
    Id = setTimeout( refreshWindow() , 100000 );
    should be
    window.setTimeout("refreshWindow()",100000);
     
    Jedi Fans, Jul 26, 2005
    #2
    1. Advertising

  3. Guest

    Hi "Jedi Fans",

    Thanks for your lightning quick response!!!!

    Such a simple error and a messy result...
    I have made the modification as suggested and, for the first run
    through, it worked - I had a form open (so the condition would prevent
    the refresh from happening) for the first cycle, and then I hid it (so
    the condition would let the refresh happen) the second time, but it
    looked like the loop ceased after the first run.

    Any further suggestions on how I can achieve this?

    Thanks
    Luke
    (Apprentice)
     
    , Jul 26, 2005
    #3
  4. Jedi Fans Guest

    wrote:
    > Hi "Jedi Fans",
    >
    > Thanks for your lightning quick response!!!!
    >
    > Such a simple error and a messy result...
    > I have made the modification as suggested and, for the first run
    > through, it worked - I had a form open (so the condition would prevent
    > the refresh from happening) for the first cycle, and then I hid it (so
    > the condition would let the refresh happen) the second time, but it
    > looked like the loop ceased after the first run.
    >
    > Any further suggestions on how I can achieve this?
    >
    > Thanks
    > Luke
    > (Apprentice)
    >

    window.setInterval instead of window.setTimeout
     
    Jedi Fans, Jul 26, 2005
    #4
  5. Guest

    Hey Jedi Fan,

    You're a scholar & a saint!

    Thanks for your help (Man, I feel like a newbie...)
    Luke
     
    , Jul 26, 2005
    #5
  6. Jedi Fans Guest

    wrote:
    > Hey Jedi Fan,
    >
    > You're a scholar & a saint!
    >
    > Thanks for your help (Man, I feel like a newbie...)
    > Luke
    >

    yvw Luke, also unless your email address doesnt mind being spammed...
    best to munge it like this:
    lucanos[at]gmailNOSPAM[dot]com or summin invalid so the spammers dont get it
     
    Jedi Fans, Jul 26, 2005
    #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. Don
    Replies:
    3
    Views:
    901
    Teemu Keiski
    Jul 9, 2004
  2. -
    Replies:
    12
    Views:
    702
    Remon van Vliet
    Jun 15, 2005
  3. Charlie@CBFC
    Replies:
    0
    Views:
    344
    Charlie@CBFC
    Jan 5, 2007
  4. Gábor SEBESTYÉN

    Unless unless

    Gábor SEBESTYÉN, Jun 17, 2005, in forum: Ruby
    Replies:
    3
    Views:
    159
    Gábor SEBESTYÉN
    Jun 17, 2005
  5. Bill W.
    Replies:
    13
    Views:
    304
    Phillip Gawlowski
    May 9, 2011
Loading...

Share This Page