Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Update a status object while in a tight loop ?

Reply
Thread Tools

Update a status object while in a tight loop ?

 
 
Richard A. DeVenezia
Guest
Posts: n/a
 
      04-03-2004
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>
 
Reply With Quote
 
 
 
 
Richard Cornford
Guest
Posts: n/a
 
      04-04-2004
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
performance of tight loop gry Python 8 12-14-2010 11:59 AM
Using malloc/free in a tight loop Navaneeth C Programming 9 11-19-2010 06:54 PM
Nice a tight loop? Joseph C Programming 16 07-07-2006 09:11 PM
while loop in a while loop Steven Java 5 03-30-2005 09:19 PM



Advertisments