Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

refresh <div> during function

Status
Not open for further replies.

jel

Programmer
Feb 17, 2002
349
NL
Hi,
I'm writing a very simple testpage, where I want to show different output from an appl.
Not knowing much (hardly anything) about javascript, it wasn't difficult to come up with:
Code:
function testrun(){
  testApp.DoSomething();
  Result.innerHTML=testApp.output;
  testApp.DoSomethingElse();
  Result.innerHTML=testApp.output;
}
[code]
Result being <div id=&quot;Result&quot;>.
Problem: testApp takes a lot of time to DoSomething, but Result is repainted only at the end of the function, so I'm staring at a blank screen for most of the time, and then only get to see the result of DoSomethingElse...
Is there something like a RePaint method to handle this?
 
>> testApp takes a lot of time to DoSomething, but Result is repainted only at the end of the function, so I'm staring at a blank screen for most of the time, and then only get to see the result of DoSomethingElse...
Is there something like a RePaint method to handle this?


Effectively, the browser &quot;locks up&quot; while your testrun function is running.

Perhaps setting up the screen painting part of your script as a loop using setTimeout to periodically check a flag on your testApp object.

The following function calls itself every half a second and updates the innerHTML of the DIV tag with the output of testApp if the readyState property of testApp has been set to &quot;ready&quot;.

Code:
function doPaint()
 if(testApp.readyState == &quot;ready&quot;){
  Result.innerHTML=testApp.output;
 }
 window.setTimeout(doPaint,500);
}

Of course to accomodate that you'll need to set up the readyState flag in your testApp object.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

AU.gif
Check out Tek-Tips Australia New Zealand forum1155
NZ.gif
 
Thanks, it worked.
It didn't solve the problem that the test-sequence was in one js-function, so I made the timer call a function that reads en evaluates the next line from a text-file.
It's a bit messy coding, but it will do...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top