Copy link to clipboard
Copied
Hey everyone,
I have a list
x = ['Foo_1','Bar_2']
Foo is the name of a field in the same form for which I need the value - I then want to check if that value is equal or lower than 1 and then store that result (as ill need to do the same for multiple items in the list)
Using the fact that the fieldname will always be three characters long I've written x.substr(0,3) which I then use to get the field value
if (this.getField(x[0].substr(0,3)).value <= x[0].substr(-1)){
//store the fact that the Foo field is lower or equal to one (in this example)
}
So my question is can I use the string resulting from x[0].substr(0,3) in the name for a variable?
when I try:
var 'state_'+x[0].substr(0,3) = 'Yep'
I get the error 'missing variable name'
Any suggestions how I can solve this?
Thank you in advance for any trouble to be taken
You can use a associative array:
var arr = [];
arr['state_'+x[0].substr(0,3)] = 'Yep';
Copy link to clipboard
Copied
You can use a associative array:
var arr = [];
arr['state_'+x[0].substr(0,3)] = 'Yep';
Copy link to clipboard
Copied
Ah very cool, yeah that works
thanks a ton bernd!