• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

PDF JS: use part of list as variable

Participant ,
Jan 24, 2020 Jan 24, 2020

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

TOPICS
Acrobat SDK and JavaScript

Views

74

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 24, 2020 Jan 24, 2020

You can use a associative array:

 

var arr = [];
arr['state_'+x[0].substr(0,3)] = 'Yep';

Likes

Translate

Translate
Community Expert ,
Jan 24, 2020 Jan 24, 2020

Copy link to clipboard

Copied

You can use a associative array:

 

var arr = [];
arr['state_'+x[0].substr(0,3)] = 'Yep';

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 24, 2020 Jan 24, 2020

Copy link to clipboard

Copied

LATEST

Ah very cool, yeah that works

thanks a ton bernd! 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines