Expand my Community achievements bar.

SOLVED

Help! Javascript not working when object moved from one page to another!

Avatar

Level 1

Hello all:

I am new to Adobe Livecycle Designer (version 8.0). I have created a 3 page interactive pdf form with numerous objects (text fields, radio buttons, drop-down boxes, etc.), that our business wants to begin using soon.

I am having difficulty with some of my Javascript not working with a few of my objects on page 2 of the form. Specifically, there is a drop-down box for "Country" on page 2 of my form. When the user selects, for example, "United States" from the list, I have Javascript that is supposed to change the "Currency" drop-down box rawValue to "US Dollars" accordingly (upon the change event).

I think my Javascript syntax is proper, but I am not certain. Here is my simple Javascript associated with the "Country" drop-down box (Note: rawValue 80 = "United States" and rawValue 105 = "US Dollars"):

-


form1.Page1.cmbContactInfoCountry::change: - (JavaScript, client) -


if (this.rawValue == 80) {     

     cmbCurrency.rawValue = 105;

     }

This seems pretty straight forward and it WORKS when my "Country" drop-down box is moved to page 1 of the form, but it WILL NOT WORK when I move the "Country" drop-down box back to page 2 of the form (which is where it belongs).

Does anyone have any suggestions or solutions? I have spent probably 6-8 hours racking my brain trying to figure out why it works when on one page, but it does not work when move to a different page. I am guessing that I may have corrupted something OR that I am not fully addressing the proper name of the object?

Please help!

Frustrated and helpless near Chicago!

Taylor T

1 Accepted Solution

Avatar

Correct answer by
Level 10

Yeah, that's a quirk of the dropdown lists...when you select an item from the ddl it isn't commited until you exit the field, unless you do the following:

if (this.boundItem(xfa.event.newText) == 1) {

     cmbCurrency.rawValue = 1;

}

else if (this.boundItem(xfa.event.newText) == 2) {

     cmbCurrency.rawValue = 2;

}

The xfa.resolveNode stuff wasn't needed as the two objects are in the same subform and as such can "see" each other.

Think of the subforms as a folder structure - items can see what's in their own folder but have to be told where to find things in other folders. So if cmbCountry was in subform1 and cmbCurrency was in subform2 the above rawValue lines would look like:

subform2.cmbCurrency.rawvalue = 1;

It's a good idea to name all your objects, subforms, etc. it makes working with scripting much easier - then you won't have to deal (as much) with things like those xfa.resolveNode chunks you had before. It put those in because you have more than one subform called "subform", the number in the square brackets is the Instance number (when you have more than one of the same object) so the program has to differentiate between the different instances of "subform".

The instance numbers come in handy though for things like table rows and the like when you need to do calculations.

View solution in original post

5 Replies

Avatar

Level 10

By moving the object to another page, and possibly a different subform you've probably broken the reference to field you're trying to operate on.

You can check this when you test in Acrobat, make sure the Console is activated (CTRL-J) and then when you test you should hopefully get an error message in the console that tells you what's going on.

I'm guessing it's the reference to cmbCurrency that isn't working?

The easiest way to get a qualified reference to another field is to use the Script Editor. With the script editor open with the script you're working on, navigate your view so you can see the field you're trying to get (don't click on anything or you'll lose focus of the script). Then click in the script editor where you want the reference to go and then hold down the CTRL key and mouse over the field you want, the mouse cursor should change to a V, then click on the field - that should insert the proper reference.

Avatar

Level 1

Hi Jono:


Thank you for your quick reply.I was able to obtain the full name of the cmbCurrency object using the method you taught me. That is brilliant! Great short-cut tool.

Unfortunately, I am still having issues with getting Javasript for the cmbCountry object to work with the cmbCurrency object. I haved pasted my new Javascript below.

JavaScript for cmbCountry object:

//UNITED STATES

if (this.rawValue == 1) {

          xfa.resolveNode("form1.#subform[1].cmbCurrency").rawValue = 1;

          }

else

//CANADA

if (this.rawValue == 2) {

          xfa.resolveNode("form1.#subform[1].cmbCurrency").rawValue = 2;

          }

I have checked the "Specify Item Values" checkbox of the cmbCurrency drop-down object and Value 1 = "US Dollars" and Value 2 = "Canadian Dollars".

When I select "Canada" from the cmbCountry drop-down object, the rawValue of the cmbCurrency drop-down object is changed to "US Dollars" (when it is clearly defined as "Canadian Dollars"). When I select "United States" from the cmbCountry drop-down object, the rawValue of the cmbCurrency drop-down object stays blank for uknown reasons. Very strange.

Since I am not able to further explain in detail on what I am experiencing, I have posted a link to my file below (I just signed up for an account at ShareFile). I would forever be indebted to you if you can help me figure this out!

https://thomptk.sharefile.com/?cmd=d&id=07ede2fe11db4549

Avatar

Correct answer by
Level 10

Yeah, that's a quirk of the dropdown lists...when you select an item from the ddl it isn't commited until you exit the field, unless you do the following:

if (this.boundItem(xfa.event.newText) == 1) {

     cmbCurrency.rawValue = 1;

}

else if (this.boundItem(xfa.event.newText) == 2) {

     cmbCurrency.rawValue = 2;

}

The xfa.resolveNode stuff wasn't needed as the two objects are in the same subform and as such can "see" each other.

Think of the subforms as a folder structure - items can see what's in their own folder but have to be told where to find things in other folders. So if cmbCountry was in subform1 and cmbCurrency was in subform2 the above rawValue lines would look like:

subform2.cmbCurrency.rawvalue = 1;

It's a good idea to name all your objects, subforms, etc. it makes working with scripting much easier - then you won't have to deal (as much) with things like those xfa.resolveNode chunks you had before. It put those in because you have more than one subform called "subform", the number in the square brackets is the Instance number (when you have more than one of the same object) so the program has to differentiate between the different instances of "subform".

The instance numbers come in handy though for things like table rows and the like when you need to do calculations.

Avatar

Level 1

Hi Jono:

The dropdown lists now work as intended--thanks to you! I cannot tell you how much I appreciate you explaining to me what was going on and how to resolve it. I will use your suggestions and guidance going forward.

If you were local, I would definitely buy you a beer at the very least. Hell, I'd even buy you a case of beer or even a keg if you wanted!

Thank you again for your time and invaluable assistance.


Sincerely,


Taylor