I have an unknown number of textboxes on my form. They will be called person(i) so if I have 3 textboxes I will have person1, person2, and person3. I want to be able to create a for loop that will loop through each one of these controls...
You just about never need to use eval; the only time I've ever seen to prove useful is to avoid scoping issues, but that isn't the case in this instance. You need to recall that the form object has an elements array in which it's child elements can be accessed though. It could be as simple as this:
for(i=0 i<theForm.elements.length; i++) theForm.elements['element' + i ].value = 'This is element ' + i + '.';
This is where theForm is a reference to the form object you want to access. The main reason you would want to avoid using eval is becuase it uses more resources than just about any other JavaScript method. It just doesn't make sense to waste precious resources when you have other (less resource heavy) methods available to you. The more calls you make to eval, the longer it will take for your script to execute, and that really isn't what you want.
Bookmarks