Dynamic Field Refrencing Using Eval

A method to simplify accessing rows or columns of fields. For some things
tables of fields are unavoidable, but are a pain to work with. By using some
simple field nameing rules and the eval function in javascript you can easily
re-use a set of variables to work with groups of fields.
Say you have a table of fields 3 rows x 3 columns like so:

A1 B1 C1
A2 B2 C2
A3 B3 C3

Instead of making 9 references to access the values of these fields, just make
three and dynamicly reasign them like so:

// Declare three global variables
var fieldA
var fieldB
var fieldC

// eval builds the object variable from the text
// rownum is the number associated with fields
// in that row
function changeRow(rownum)
{
// This is a string, not an object;
var f = "document.forms[0].";

//Modifies the global variable
fieldA = eval(f + "A" + rownum);
fieldB = eval(f + "B" + rownum);
fieldC = eval(f + "C" + rownum);
}

// Now access things easily in your functions
function doSomething()
{
var x //Index of For Loop
for(x=1;x<=3;x++)
{
changeRow(x) //sets the globals to row x
fieldA.value = "Hello";
fieldB.value = "World";
fieldC.value = ":-)"
}
}

Dig Deeper on Domino Resources - Part 4

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close