Solved

force refresh/repaint screen while processing?

Posted on 2003-11-21
5
1,429 Views
Last Modified: 2008-03-17
I have something like:

for(i=0; i<10; i++)
{
  document.all.textboxProcess.value = i;
  process(i);
}

But the value of textboxProcess is not updated until the loop finish.
How can I force screen refresh/repaint inside the loop?
0
Comment
Question by:Hardi
  • 2
  • 2
5 Comments
 

Accepted Solution

by:
splamunge earned 30 total points
ID: 9801996
You have to give the GDI a timeslice, so it can repaint, try ...

<html>
  <body>
    <form>
      Test value here: <input type=text id="textboxProcess" name="textboxProcess" size=8 maxlength="8" value="-1">
    </form>
    <script language="javascript">
      var upperLimit = 10, updateTO = 0, msec = 100;
     
      function advanceTick(newTick){
        if(!newTick){newTick = 0;}
        if(newTick < upperLimit){
          document.all.textboxProcess.value = newTick.toString();
          newTick++;
          updateTO = window.setTimeout('advanceTick(' + newTick + ')', msec);
        }
      }
     
      onload=advanceTick;
    </script>
  </body>
</html>

... Adjust msec upward or downwards until it looks right.
0
 
LVL 6

Author Comment

by:Hardi
ID: 9802051
umm... thanks
so there is no way you can do such as
window.repaint;
or anything?

i'll try that advanceTick...
0
 
LVL 11

Expert Comment

by:Zontar
ID: 9802053
Don't use document.all. You scripts will run much more efficiently without it, and your scripts will also run cross-browser.

Use document.forms[0].textboxPorcess.value or document.getElementById("textboxProcess").value instead:

<html>
<head>
<script language="javascript">
  var upperLimit = 10, msec = 200;

  function advanceTick()
  {
    var newTick = document.getElementById("textboxProcess").value;
    if(newTick < upperLimit)
    {
      document.forms[0].textboxProcess.value = ++newTick;
      timer = setTimeout("advanceTick()", msec);
    }
  }

  window.onload = advanceTick;
</script>
</head>
<body>
<form>
Test value here: <input type="text" id="textboxProcess" name="textboxProcess" size="8" maxlength="8" value="-1">
</form>
</body>
</html>

Also the toString() call isn't necessary, and you can just get the value from the text input.

This also has the advantage that it will work in all JS-capable browsers.
0
 
LVL 11

Expert Comment

by:Zontar
ID: 9802078
> window.repaint;

Clientside JS doesn't give you that sort of fine-grained control over graphics/screen.

Remember, a Web browser is essentially just a glorified document viewer. ;^)
0
 
LVL 6

Author Comment

by:Hardi
ID: 9802381
thanks splamunge and Zontar
my code is now messed up coz it's not that simple =P
but i know how to use setTimeout
and i'll start using getelementbyid =)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question