Using variable variables to retrieve values

I’ve named series of fields sequetially. I’m trying to loop through them and test the value of each to a certain value. I can loop through and change properties of the element but I can’t seem to get the value.

for (var i=1;i<=10;i++)
{
var series_name = ‘series_’ + i

if (elements[series_name].value == ‘target’)
// This is the line I’m having trouble with. The eval() or the .value
// command would work in javascript.
{
// take action here
}
}

sls2000:
I’ve named series of fields sequetially. I’m trying to loop through them and test the value of each to a certain value. I can loop through and change properties of the element but I can’t seem to get the value.

for (var i=1;i<=10;i++)
{
var series_name = ‘series_’ + i

if (eval(series_name) == ‘target’)
{
// take action here
}
}

eval() works fine in Servoy…

sls2000:
I’ve named series of fields sequetially. I’m trying to loop through them and test the value of each to a certain value. I can loop through and change properties of the element but I can’t seem to get the value.

for (var i=1;i<=10;i++)
{
var series_name = ‘series_’ + i

if (elements[series_name].value == ‘target’)
// This is the line I’m having trouble with. The eval() or the .value
// command would work in javascript.
{
// take action here
}
}

Note that in Servoy there is a strict separation between design and data. The element node refers to the graphical representation of a field and not to the data. Use controller.getDataProviderValue(series_name) to get to the value.

swingman:

sls2000:
I’ve named series of fields sequetially. I’m trying to loop through them and test the value of each to a certain value. I can loop through and change properties of the element but I can’t seem to get the value.

for (var i=1;i<=10;i++)
{
var series_name = ‘series_’ + i

if (eval(series_name) == ‘target’)
{
// take action here
}
}

eval() works fine in Servoy…

eval works fine in Servoy but should be avoided as much as possible (and not just in Servoy but in any javascript script).

Hello Jan,

could you explain exactly why? Is it because it can’t be compiled somehow?

Thanks
Patrick

patrick:
Hello Jan,

could you explain exactly why? Is it because it can’t be compiled somehow?

Thanks
Patrick

Eval is slow (interpreted) and potentially insecure (if you eval field contents for example people could execute arbitrary code)