Solved

force refresh/repaint screen while processing?

Posted on 2003-11-21
5
1,436 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

740 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