Get Field Object / Value Using Field Name via Eval Function

Mindwatering Incorporated

Author: Tripp W Black

Created: 01/10/2006 at 12:58 PM


Notes Developer Tips

The form has a field that contains the name of a field. You want to get the field name and then get the field itself to write a new value to it.


var thisfrm;
var openfrm;
var openerSendTo;

// setup forms for this dialog and the form in the originating/parent window
thisfrm = document._FormName;
openerform = window.opener.document._FormName;

// setup working variables
openerSendTo = eval('openerfrm' + thisfrm.tmpSendToFld.value); // tmpSendToFld contains name of field to load

... do some code ...

// update opener SendTo field
openerSendTo.value = thisfrm.tmpSendTo.value

// optionally refresh based on new value
// window.opener._doClick('$Refresh', this, '_self', '#RefreshKW_' +

// close this dialog

Second Solution:
Using a hidden flag field, get from that field, the name of a second field.
Using the name get the second field. Looping through [elements] on form isn't an option.

Use the Eval. See code sample below.

var vfldnm = f.FlagFld.value;
if(vfldnm !="") {
var vfld = eval('f.' + vfldnm);
... do reset of code here ... ;

previous page