[thelist] Using variables in DOM object names
Ryan Rushton
web at ryanrushton.com
Tue Jul 12 21:31:18 CDT 2005
I am setting values in one form (StudentReg) with values from another form
in a popup window (studentSelect).
The line for setting one form field looks like this:
window.opener.document.studentReg.ContactFirstName.value =
window.document.studentSelect.ContactFirstName.value;
Because there are many form fields to set, I would like to place them in
an array and loop over the array, but I don't know how to properly refer
to the objects when they have a variable within their name. Here is my
NON-working code:
var fieldnames = new
Array("ContactFirstName","ContactLastName","Address","City","etc")
for (i=0; i<fieldnames.length; i++)
{
eval('window.opener.document.studentReg.' +fieldnames[i] +'.value') =
eval('window.document.studentSelect.' +fieldnames[i] +'.value');
}
Any help with this would be greatly appreciated!
More information about the thelist
mailing list