Refresh Page - Unless Condition

L

lucanos

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
 
J

Jedi Fans

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
<SNIP>
Id = setTimeout( refreshWindow() , 100000 );
should be
window.setTimeout("refreshWindow()",100000);
 
L

lucanos

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)
 
J

Jedi Fans

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
 
L

lucanos

Hey Jedi Fan,

You're a scholar & a saint!

Thanks for your help (Man, I feel like a newbie...)
Luke
 
J

Jedi Fans

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top