elements.something.visible=true

I know I’m beeing pushy…
But i was wondering if we could use variables in the functions that deal with elements…

Suppose I have 5 stripes (stripe1 thru strip2) on a form, normally we would do:

elements.stripe1.visible=true;
elements.stripe2.visible=true;
elements.stripe3.visible=true;
elements.stripe4.visible=true;
elements.stripe5.visible=true;

It would be fun if we could use a variable for the elementname. We could use a loop defining the elementname…for example (hope i got the syntax right)

for ( var i = 1 ; i < 6 ; i++ )
{
var thingie=‘stripe’+i;
elements.thingie.visible=true;
}

Just brainstorming over here in Rotterdam

You can build up a textstring like that and then evaluate it, using eval(…)

Paul

this will work:

elements.stripe1.visible=false;
elements.stripe2.visible=false;
elements.stripe3.visible=false;

for ( var i = 1 ; i <= 3 ; i++ )
{
var thingie=‘stripe’+i;
elements[thingie].visible=true;
application.sleep(1000)//wait 1 sec
}

I’m gonna buy Javascript for Dummies right away :wink:

Thkx guys

I’m assuming the delay in the loop is to allow Servoy to catch up with the interface. Is the 1 second wait time arbitrary? Could one get by with say .10 second for each element? If you have a lot of elements on a form a 1 second wait time could get expensive.

No, you can leave out the delay.
It’s just for seeing script at work. :)