Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Using a variable in an object name.

Avatar

Level 2

Hi,

I have 15 text fields each with 6 check boxes.

I would like to copy the text fields to new fields depending on which checkbox's are checked.

This also needs to be in a loop.

I need to know how to add a variable into a textfield name?

My code is basically like this:

var x = 1;

while (x<15)

     {if (Page1.CheckP// insert the value of x //S1.rawValue==1)

                    {Pax// insert the vaule of x //Sect1.rawValue=PaxName1

               x=x+1};

     }

I am using Adobe Designer.

Thank you in advance.

Damo.

5 Replies

Avatar

Level 10

Hi Damo,

There are several ways, you could use pure JavaScript property references, so;

 

Page1.CheckP["TextField1"].rawValue

or you could pass the field name into the resolveNode method, so;

Page1.CheckP.resolveNode("TextField1").rawValue

There is a bit more on this in John Brinkman's blog http://blogs.adobe.com/formfeed/2008/12/object_expressions_in_xfa.html

Regards

Bruce

Avatar

Level 2

This doesn't seem to help me.

I have managed the following:

var x = 1;

var vCheck="Page1.CheckS1P"+x;

if (vCheck.rawValue==1)

          {Pax1Sect1.rawValue=PaxName1};

I have confirmed vCheck = Page1.CheckS1P1 but the IF statement still does not work.

Avatar

Level 10

Hi,

Try changing the second line to

var vCheck=Page1["CheckS1P"+x];

Also, try adding

app.alert(vCheck.rawValue)

after this line, just to confirm you are referenceing the form object CheckS1P1 and not the address of the form object.

I would have expected your code to throw an exception as vCheck will be a string variable which wont have a rawValue property, what event do you have this code in and do you have "When exception is throw" set to break under Edit ... Preferences ... JavaScript of Acrobat (not Designer).

Regards

Bruce

Avatar

Level 2

Hi Bruce,

I am running this code in a 'on click' event on a button.

Basically, I have 5 passenger names each with 6 CheckBox's for 6 sectors.

If Checkbox1 (Sector 1) is checked, I want to put the passenger name in a textfield. Then look for the next passenger on sector 1 and put them in the next textfield.

This needs to be done for each sector.

So this is what I have:

var PaxName1=Page1.PaxName1.rawValue;  // and all other passenger names.

// Sector 1

var x = 1;

while (x<5)

     var vCheck=Page1["CheckS1P"+x];

     if (vCheck.rawValue==1)

          {[TextField"+X].rawValue = PaxName''+X;

            x=x+1};

Hope this explains what I am trying to do.

Avatar

Level 10

Hi,

It is a bit hard to say without seeing the structure of your form, but the form element references on the line "{[TextField"+X].rawValue = PaxName''+X;"  will have to follow the same pattern for setting vCheck, so something like, {Page1["TextField"+X].rawValue = Page1["PaxName"+X].rawValue.

Otherwise you might have to host the form somewhere and post a link in this thread so we can have a look, you can use Acrobat.com, or Google Docs, whatever system you have an account for.

Bruce