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);
}
I'd suggest:
1. Create an array, e.g. myformstatus[]
1a. Set a new variable to setInterval("is Complete(myform )",20);
2. have a for loop disabling all the form elements, assuming that you
don't want user interaction until the process is complete, just user
feedback. Populate each element of myformstatus[] with a default value,
e.g. null.
3. use your loop with something like myform[i] =
setTimeout(chec hkValidity(i),1 0); so your function is called and the
browser is only hanging for the period of one execution of
chechkValidity( ) once.
[Note your setTimeout could be
("chechkValidit y(i);chechkVali dity(i+1);chech kValidity(i+2); ",10"); so
that these are executed in blocks rather than just one at a time,
depending on how intensive each call is...]
4. In chechkValidity( ), set myformstatus[i] to some other default value,
e.g. "done"
5. Create a function isComplete() which goes through myformstatus[] to
check that all elements have a value of "done". If so, clear the
setInterval() and then have a for loop reenabling all form elements.
Then in your step 3 or 4 you can do whatever feedback to the user you can.
Note this may cause the overall process to take _longer_, but if you do
it in one for loop as you've described you'll hit three problems:
1. It may cause the browser to freeze so long that the browser offers
the option for the user to abandon it, thus potentially causing all
manner of state-related problems. I've found that recent builds of
Mozilla seem to have shortened this time considerably, but there's no
easy way I've found of pre-determining how long this actually is.
2. You won't be able to get feedback to the user, as the browser needs
time to breathe between bursts of Javascript...
3. A browser freeze may be considered by the user as a browser crash!
Just my thoughts - I've not tested this out but it seems to make sense,
at least to me!
Thanks,
Ian