Click to See Complete Forum and Search --> : For loops - without document.write()


Shambler
11-25-2003, 03:36 AM
Hi

Ok, I have a lot of forms that need to be reset when pressing a button.

I currently have a resetForms()-function containing something like this:

document.checkform1.reset();document.checkform2.reset(); ........

With quite a lot of forms, this yells for a forloop.. how would I do this without using the document.write-function? I would like to do something like this:



var maxNumberOfForms = 42;
var i;
for(i=0; i<maxNumberOfForms; i++) {
"document.checkform"+i+".reset()";
}



(I know this syntax is erroneous, but pseudo-wise this is what I would like it to do)

As far as I'm concerned the document.write() (or document.writeln())-functions write a new file with the specified text? Or?

Thanks in advance :)

Gollum
11-25-2003, 04:01 AM
var maxNumberOfForms = 42;
var i;
for(i=0; i<maxNumberOfForms; i++)
{
document['checkform'+i].reset();
}

Shambler
11-25-2003, 04:04 AM
Thanks a lot Gollum :) (in this case it would be "Smeagol - the helpful", no? :D )

Gollum
11-25-2003, 04:26 AM
Pleasssure for sure:cool: