Set Multi-Value Field using JavaScript where Field Name is dynamic

I am trying to set a multi-value field in Javascript, but the field name is dynamic — that is, the name is determined by a number…

The form is has the fields defined on it, however, are shown/hidden/populated through Javascript, so when the form is reopened, we have to populated the fields again…

Here is the code that I am working on:

function editQuery(myForm) {

// Get the row filters that were used in the last query...

for (f = 1; f < 16; f++) {

	filter = eval("myForm.FilterList_" + f)

	if (filter.selectedIndex > 0) {

		var savedFilterMethodValue =  eval("myForm.FilterMethod_" + f + ".value");

		var savedFitlerValues = eval("myForm.FilterChoices_" + f + ".value");

		displayNextFilter(f); // display it

		updateFilters(this); // update the filters

		// take the saved methods and values and then update the selections

		}

}

}

The problem is, I can get the value of the field:

var savedFilterMethodValue = eval(“myForm.FilterMethod_” + f + “.value”);

But how do I populate it? This won’t work (can’t put the eval statement on the left), but guessing something like this:

eval(“myForm.FilterMethod_” + f + “.value”) = savedFilterMethodValue;

Or is there an easier way?

Thanks!

Dan

Subject: Set Multi-Value Field using JavaScript where Field Name is dynamic

If you feel you absolutely must use eval(), you’d use it on the whole statement:

eval(“myForm.FieldName_” + i + ".value = " + value);

That’s only if you feel you absolutely have to use eval() – AFTER you find out that you can use the elements collection of the form, which takes a string argument for the fieldname or button name:

myForm.elements[“FieldName_” + i].value = variable;

or

variable = myForm.elements[“FieldName_” + i].value;

No eval(), easier to read, faster to execute (not that it really matters in a typical short Domino script, but it can make a big difference in a long, complex script).

Subject: RE: Set Multi-Value Field using JavaScript where Field Name is dynamic

So, seems like I should avoid eval()…

Sounds good to me — thanks again Stan!

Thanks!

Dan