Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

force refresh/repaint screen while processing?

Posted on 2003-11-21
5
Medium Priority
?
1,457 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 120 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

604 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