473,382 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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>
Jul 23 '05 #1
1 1664
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.
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mohammed Mazid | last post by:
Can anyone please help me here? Basically I have modified the source code and understood it but when I update a record in the db using a JSP, it gives me an error "The flight you selected does...
4
by: Laurent Compere | last post by:
Hi all, I try to make a logo fade in. I wrote the code below that is simple and supposed to be compatible with IE6,Firefox and Netscape. It works pretty well under IE6 but under Firefox and...
0
by: Anthony Robinson | last post by:
I have a stored procedure that needs to loop through a record set, evaluate value, then either perform an operation or move tro the next record - depending on some criteria. Here's the procedure:...
18
by: Bill Smith | last post by:
The initial row is inserted with the colPartNum column containing a valid LIKE pattern, such as (without the single quotes) 'AB%DE'. I want to update the column value with the results of a query...
3
by: Ray | last post by:
I am having my first experience using BLOB as a row in a table. I am using it to insert graphics for labels we print. I have no problem inserting into and select from the table. The graphic is...
4
by: Lada 'Ray' Lostak | last post by:
Hello there, I am thinking how to solve another typical problem of online systems with combination of thin client... Imagine simple case, 2 users are going to edit 'same' datas. Both see on the...
5
by: devi | last post by:
hi, I am creating a simple bug tracker application (in Access db) and i created a hisotry table to log the bug history. The history table contains details like ProblemRecordNo (PRN),...
1
by: Christian Rühl | last post by:
hey! what i wanna do sounds very simple at first, but it turned out to be a real bone crusher... i want to check if a treeView node is checked and if a correspondent node in my xml config file...
1
by: teenagelcruise | last post by:
hi, i have a problem with my code which is i cannot update and addnew data into the database but i can delete the data.plz give me an idea.this is my code that i wrote. <html> <head> <meta...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.