[work] [thelist] more loops... this time, javasctipt
Hershel Robinson
hershelr at netvision.net.il
Tue Aug 23 12:55:44 CDT 2005
> My question is, there's gotta be a better way, than to copy this over 27
> more times for each of the remaining questions, changing q1 to q2, q3,
> and so on up to q28.
Yes, sounds like a job for computerization. :)
> Basically, what i need to do is wrap the for loop in another loop, which
> counts from 0 to 27 (or 1 to 28), incrementing the question variable.
The precise syntax you can figure out, but you have two options I
believe. One is to use something like:
document.getElementById("q"+i)
to access the ith q question where i is your loop variable. Another
option is to use something like:
theform.elements["q"+i]
which would probably be more efficient and wouldn't have the pitfalls of
ids not matching names. I myself would recommend this method.
> If I remember correctly, I need to use the eval() function to evaluate
> 'q'+x before i use it as a field label.
That would work, but I wouldn't recommend it. Using eval() for such a
purpose is far from good programming practice.
Hershel
More information about the thelist
mailing list