![]() |
Update a status object while in a tight loop ?
A page has a long running computation loop.
While in the loop I want to update a status object so I know how things are going in the computation. This is what I have, but it doesn't seem to update my status object. Thanks, Richard <html> <head> <script type="text/javascript"> function compute() { var status = document.getElementById ('status') var result = document.getElementById ('result') var j = 0; var n = 1e6; var p = n/10; // tight loop for (var i=0;i<n;i++) { // if (j++ > p) { j=0; status.value = i; } if (j++ > p) { j=0; setTimeout ( function(){status.value=i} , 1) } } setTimeout ( function(){status.value='Compute'} , 1) result.innerHTML = "Computation results " + i return false } </script> </head> <body> <form name='data'> N <input name=N type=text value=5 size=4> <input id=status type=submit value='Compute' onClick="return compute(document.forms.data.N.value)" > </form> <div id=result></div> </body> </html> |
Re: Update a status object while in a tight loop ?
Richard A. DeVenezia wrote:
<snip> > // tight loop > for (var i=0;i<n;i++) { > // if (j++ > p) { j=0; status.value = i; } > if (j++ > p) { j=0; setTimeout ( function(){status.value=i} , 1) } The setTimeout function is not able to interrupt executing code. No execution scheduled within this function will get an opportunity to happen until the - compute - function returns (along with the event handler that called it). <snip> > </script> > </head> > <body> > <form name='data'> > N <input name=N type=text value=5 size=4> > <input id=status type=submit value='Compute' > onClick="return compute(document.forms.data.N.value)" <snip> ^^^^^^^^^^^^^^^^^^^ this.form.N.value But the - compute - function has no parameters. Richard. |
| All times are GMT. The time now is 01:20 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.