473,725 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to express progress of longer run of JS?

Hi,
I check data validity in html form by JS. Something like

for (i=0; i<document.for m[0].elements.lengt h; i++) {
chechkValidity( i);
}

Unfortunately, the form[0] has about two thousands elements (it is
statistical questioning form for companies) and execution of this one
cycle takes about twenty seconds.

The problem is, that during these 20 seconds the browser "freezes":
The button activating the cycle disappears and the mouse pointer
doesn't change into "watch" (sandglass) showing that something is
being carried out.

Although after the 20s everything is ok, it is not the nicest behavior
of the form. I don't assume somebody is so impatient to restart during
those 20 seconds. I just want to minimize the users' swearing on my
address and tha's why my question:

??? How to show the progress of that cursed for-cycle?

Thanks
Martin
Jul 23 '05 #1
13 2192
On 18 May 2004 07:17:43 -0700, mr****@compik.f d.cvut.cz (Martin
Mrazek) wrote:
Hi,
I check data validity in html form by JS. Something like

for (i=0; i<document.for m[0].elements.lengt h; i++) {
chechkValidity( i);
}

Unfortunatel y, the form[0] has about two thousands elements (it is
statistical questioning form for companies) and execution of this one
cycle takes about twenty seconds.

The problem is, that during these 20 seconds the browser "freezes":
The button activating the cycle disappears and the mouse pointer
doesn't change into "watch" (sandglass) showing that something is
being carried out.

Although after the 20s everything is ok, it is not the nicest behavior
of the form. I don't assume somebody is so impatient to restart during
those 20 seconds. I just want to minimize the users' swearing on my
address and tha's why my question:

??? How to show the progress of that cursed for-cycle?

Thanks
Martin


Could you possibly have it display a message informing the user to
please wait and the process can take up to 30 seconds.....
Josh Austin
System Administrator
Agent Services of America
ksadmin NOSPAM @comcast.net
www.agentsvs.com (coming soon)
Jul 23 '05 #2
On 18 May 2004 07:17:43 -0700, Martin Mrazek wrote:
for (i=0; i<document.for m[0].elements.lengt h; i++) {
chechkValidity( i);
}


tried?

for (i=0; i<document.for m[0].elements.lengt h; i++) {
chechkValidity( i);
if ( i%100==0 ) {
window.status( "Processing : " + i );
}
}

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #3
Ivo
"Martin Mrazek" wrote
I check data validity in html form by JS. Something like

for (i=0; i<document.for m[0].elements.lengt h; i++) {
chechkValidity( i);
}

Unfortunately, the form[0] has about two thousands elements (it is
statistical questioning form for companies) and execution of this one
cycle takes about twenty seconds.
Submit the unvalidated form to the server. Validate it there.
Two reasons:
1. You need to do this anyway for the js-less and code manipulators.
2. It may well be much faster, including the traffic.
The problem is, that during these 20 seconds the browser "freezes":
The button activating the cycle disappears and the mouse pointer
doesn't change into "watch" (sandglass) showing that something is
being carried out.
To do this would require setting a timeout, as any visual effect of scripts
(setting the wait cursor) is only displayed after the script has finished
running. So the form submission would have to be canceled initially etc etc.
I think you 're in for a mess if you go this way.
Ivo
Although after the 20s everything is ok, it is not the nicest behavior
of the form. I don't assume somebody is so impatient to restart during
those 20 seconds. I just want to minimize the users' swearing on my
address and tha's why my question:

??? How to show the progress of that cursed for-cycle?

Thanks
Martin

Jul 23 '05 #4
Martin Mrazek wrote:
<snip>
Unfortunately, the form[0] has about two thousands elements (it is
statistical questioning form for companies) and execution of this one
cycle takes about twenty seconds. <snip> ??? How to show the progress of that cursed for-cycle?


To get the browser to re-draw it's display you have to give it a bit of
time to itself, which means stopping javascript execution and then
restarting it with a timeout of some sort. You cannot sensibly do that
in the onsubmit handler of a form without absolutely cancelling the
submission, leaving the only option to programmaticall y submit the form
when the validation is finished.

Of course inserting regular timeouts into the validation will make it
even slower.

It would probably be more sensible to look into the efficiency of your
code as even for 2000 elements 20 seconds seems very slow.

Richard.
Jul 23 '05 #5
On Tue, 18 May 2004 15:58:52 GMT, Andrew Thompson wrote:
for (i=0; i<document.for m[0].elements.lengt h; i++) {
chechkValidity( i);
if ( i%100==0 ) {
window.status( "Processing : " + i );
Of course, you will need to change
that bit to actual Javascript.
...left as an exercise for the user. ;-)
}
}


--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #6
Ivo
"Andrew Thompson" <Se********@www .invalid> wrote
On Tue, 18 May 2004 15:58:52 GMT, Andrew Thompson wrote:
for (i=0; i<document.for m[0].elements.lengt h; i++) {
chechkValidity( i);
if ( i%100==0 ) {
window.status( "Processing : " + i );


If you had either tried out your own script, or read the other posts in this
thread, you 'd have known why this will not give you your updating
statusbar, and refrained from elaborating.
Ivo
Jul 23 '05 #7
On Tue, 18 May 2004 18:53:03 +0200, Ivo wrote:
"Andrew Thompson" <Se********@www .invalid> wrote
On Tue, 18 May 2004 15:58:52 GMT, Andrew Thompson wrote:
for (i=0; i<document.for m[0].elements.lengt h; i++) {
chechkValidity( i);
if ( i%100==0 ) {
window.status( "Processing : " + i );


If you had either tried out your own script,


Vis.
....
<script type='text/javascript'>
function doCount() {
for (i=0; i<2000; i++) {
for (jj=0; jj<1000; jj++) { }
if ( i%100==0 ) {
window.status = 'Processing: ' + i/100;
}
}
window.status = '';
}
</script>

</head>
<body onLoad='doCount ();'>

(shrugs) Seems to work in both IE6 and
Moz 1.3 on XP. Did I miss something (still)?

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #8
Martin Mrazek wrote:
Hi,
I check data validity in html form by JS. Something like

for (i=0; i<document.for m[0].elements.lengt h; i++) {
chechkValidity( i);
}

Unfortunately, the form[0] has about two thousands elements (it is
statistical questioning form for companies) and execution of this one
cycle takes about twenty seconds.

The problem is, that during these 20 seconds the browser "freezes":
The button activating the cycle disappears and the mouse pointer
doesn't change into "watch" (sandglass) showing that something is
being carried out.

Although after the 20s everything is ok, it is not the nicest behavior
of the form. I don't assume somebody is so impatient to restart during
those 20 seconds. I just want to minimize the users' swearing on my
address and tha's why my question:

??? How to show the progress of that cursed for-cycle?

Thanks
Martin


I don't know what you're doing that's taking 20 seconds to iterate over
2000 form elements, but the first thing I'd do is try to resolve that.
First, you can improve performance by caching fully-qualified DOM
references so the loop doesn't have to parse the DOM everytime it
executes:

var formElements = document.forms[0].elements;
for (i=0; i<formElements. length; i++) {
checkValidity(f ormElements[i]);
}

The reason to pass the reference to the current element to checkValidity()
is so that checkValidity() doesn't have to look up the reference to the
element all over again. So instead of:

function checkValidity(i ) {
var element = document.forms[0].elements[i];
// ... handle "element"
}

it is:

function checkValidity(e lement) {
// ... handle "element" - notice not additional lookup on the element

Now that that is out of the way, let's assume that the application is
Intranet based, or at least you have control over the environment (no
popup blockers, a limited range of browsers in use, etc). If that's the
case, you could do something like:

progress.html:
---

<body onload="if (opener && opener.startPro cessing)
opener.startPro cessing();">
<!-- transparent.gif is a 1 x 1 transparent GIF image -->
<span style="backgrou nd-color:Green;">< img name="progress"
src="/Graphics/transparent.gif " width="1" height="20" /></span>
</body>

progressText.ht ml:
---

<form>
<script type="text/javascript">
for (var i = 0; i < 2000; i++) {
// this is just for testing, obviously this would be your real form
document.writel n('<input type="hidden" />');
}
</script>
<input type="button" value="Go" onclick="go();" />
</form>

<script type="text/javascript">
function go() {
// triggered by the user's action to process the form
// opens a new window with the progress meter, you may
// want to try to position it
window.progress Meter = window.open('pr ogress.html', 'progressMeter' ,
'height=100,wid th=300');
}
function startProcessing () {
// triggered by the completed loading of
// the progress meter window
var formElements = document.forms[0].elements;
for (i = 0; i < formElements.le ngth; i++) {
if (i % 10 == 0) {
// update the image once for every 10 elements
// using a setTimeout() helps prevent locking the
// browser entirely and makes this whole thing
// a little bit friendlier to the user
var t = setTimeout('sho wProgress();', 100);
}
// checkValidity(f ormElements[i]);
}
}
function showProgress() {
// triggered once for every 10 form elements processed
if (window.progres sMeter &&
window.progress Meter.document &&
window.progress Meter.document. images &&
window.progress Meter.document. images['progress']) {

window.progress Meter.document. images['progress'].width += 1;
}
}
</script>

This seemed to work pretty well in IE and Opera 7, making a smooth
expanding image. In Firefox, the green line jumped from 1 pixel wide to
200 pixels wide. Either it iterated through the form MUCH faster (which it
probably did), or Gecko-based browsers don't update the UI when there is
processing intensive JS running (which I've seen before).

Don't forget, adding all this fluff will make the actual form processing
much slower as well. Far better to fix the performance issue in the form
processing instead.

--
| Grant Wagner <gw*****@agrico reunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #9
Andrew Thompson wrote:
<snip>
(shrugs) Seems to work in both IE6 and
Moz 1.3 on XP. Did I miss something (still)?


We try not to think in terms of "both browsers" these days. But you will
find that Mozilla includes the option of disallowing scripts from
updating/modifying the status bar.

Richard.
Jul 23 '05 #10

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

Similar topics

0
1403
by: mirandacascade | last post by:
O/S - Windows XP Home with Service Pack 2 Vsn of Python: 2.4 (from ActiveState) This question is with regard to the progress bar controls that are in the file status.py. On my workstation, status.py is located in the: c:\python24\lib\site-packages\pythonwin\pywin\dialogs\ folder.
1
2852
by: Matt Alanzo | last post by:
On another newsgroup an Access knowledgable party posted: >You should be able to connect an Access ADP to an existing SQLExpress >database running in SQLS 2000 compatibility mode. The only thing you >won't be able to do is access any of the design surfaces for SQLS >objects in the ADP. I checked with the Access team on this :-) > I appealed for clarification but without reply. Maybe somone on this newsgroup can provide insight.
1
1649
by: Ziggy | last post by:
Please excuse this elementary question...but I am just dumb.... I have taken a simplistic Dialog Box and added a Progress Control. When I did that, my Dialog Box was no longer able to intialize using the DialogBox macro. If I remove the Progress Control from the form, the form displays appropriately. Is there something that needs to be done in addition to providing a callback
5
1749
by: Lloyd Sheen | last post by:
I used the betas and they had lots of problems. Well the release is here and is crap. I execute a program and then on second execute (no changes to the source) and I get the following: An error occurred creating the form. See Exception.InnerException for details. The error is: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "ObjectShower.ObjectShower.resources" was correctly...
11
4872
by: processoriented | last post by:
Hi, I'm something of a noob at this, but here it is... I have an app that fills a dataset from a SQL database, and then writes the dataset to an xml file. Everything is a SELECT query... I am basically just replicating data to the local user's machine, and several of the queries take a long time to run over VPN connection to the database (the way most of my users will use it), so I sank the whole operation into a BackgroundWorker so that...
14
2292
by: Professor Yonce | last post by:
I have made form for E-Mail. I have entered code but the Import system does not work. It has squiggly line underneath it showing it is not communicating. It Will not build. Public Class Form3Bio1 System.Net.Mail.SmtpClient Imports System.Net.Mail ' This line before ' does not work. I have the rest of code to try if and when I am able to get System working. ' I XXX out certain entrys below just for this publication.
5
1349
by: Marco Trapanese | last post by:
Hi, I have a small application which uses a connection to a SQL database. Using clickonce I make the deploy folder. Well, the target PC is old (600 MHz, 256 MB RAM, WinXP) but it should be ok for my application. The framework is installed, but while deploying my program, it want to install Windows Installer 3.1 and SQL Server Express. The former has no problem but the latter goes in timeout after downloading and installing up to 100%...
8
2076
by: Paulo | last post by:
Hi, while the user is uploading a file, is possible to show a progress bar? Using VS 2005 Asp.net 2.0 C# Thanks!
1
1392
by: coolsti | last post by:
Here is a strange occurrance: I start up my Visual C# 2008 Express program today, start a new project, put a bunch of controls on a form, save the project, and then close the program (for a break) and start it up again after. I reload my project, and it is empty. No form, no controls. I try again. And again. The same continues to happen. Anyone know what can be wrong? I did not register my Visual C# 2008 Express as it had been warning me...
0
8888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9174
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8096
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4782
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.