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

Acrobat Pro DC, Need Help w/JavaScript Code Not Working Completely

Community Beginner ,
Apr 14, 2019 Apr 14, 2019

I'm running a JavaScript for a dropdown box in a form I'm making in Pro DC, most of the code works except for the last six dropdown choices listed as "Compressor-1 Capacitor:" thru "Compressor-6 Capacitor:".

​Listed below is my code, can you tell me whats wrong and if you could edit it so that all choices work?

// Place all prepopulation data into a single data structure

var UnitData = { "Condenser Motor-1 Amps:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Condenser Motor-2 Amps:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Condenser Motor-3 Amps:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Condenser Motor-4 Amps:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Condenser Motor-5 Amps:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Condenser Motor-6 Amps:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Condenser Motor-1 Capacitor:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Condenser Motor-2 Capacitor:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Condenser Motor-3 Capacitor:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Condenser Motor-4 Capacitor:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Condenser Motor-5 Capacitor:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Condenser Motor-6 Capacitor:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Compressor-1 Amps:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Compressor-2 Amps:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Compressor-3 Amps:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Compressor-4 Amps:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Compressor-5 Amps:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Compressor-5 Amps:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Compressor-6 Amps:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Compressor-1 Capacitor:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Compressor-2 Capacitor:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Compressor-3 Capacitor:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Compressor-4 Capacitor:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Compressor-5 Capacitor:":{ rated: "Rated:",

                              actual: "Actual:" },

                 "Compressor-6 Capacitor:":{ rated: "Rated:",

                              actual: "Actual:" }};

function SetFieldValues(cUnitReport)

{

  this.getField("rated").value = UnitData[cUnitReport].rated;

  this.getField("actual").value = UnitData[cUnitReport].actual;

}

TOPICS
Edit and convert PDFs
4.5K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Apr 15, 2019 Apr 15, 2019

Yes, and as I suspected there's a mismatch in the values. The value of "Compressor-1 Capacitor:" actually has two spaces at the end of it, which is why your code is not working.

View solution in original post

Translate
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
Community Expert ,
Apr 14, 2019 Apr 14, 2019

Where does you use the function?

Translate
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
Community Beginner ,
Apr 15, 2019 Apr 15, 2019

In two fields next to the dropdown box. One called rated and the other called actual.

Translate
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
Community Expert ,
Apr 15, 2019 Apr 15, 2019

You can use the function at validation of the dropdown list.

Translate
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
Community Beginner ,
Apr 15, 2019 Apr 15, 2019

How would that validation be written?

Im very new to this and need all the help I can get.

Translate
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
Community Beginner ,
Apr 15, 2019 Apr 15, 2019

Also why would everything else work except the last six choices?

Translate
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
Community Expert ,
Apr 15, 2019 Apr 15, 2019

How did you call the function?

Translate
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
Community Beginner ,
Apr 15, 2019 Apr 15, 2019

Bernd,

This is the form. Ive edited everything out except the dropdown box and two fields we are talking about. All JavaScripts are listed as well.

Thank you for your help and if you can correct the problem and let me know what you did that would be very helpful.

Patrick Dees

Commercial Service Technical Team Leader

Translate
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
Community Expert ,
Apr 15, 2019 Apr 15, 2019

You can't attach files here. Upload it to something like Google Drive, Dropbox or the Adobe DC and post a link to it.

My guess is the values in your code don't match those in your field. Even a single missing space will cause it not to work. It has to match exactly​.

Translate
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
Community Beginner ,
Apr 15, 2019 Apr 15, 2019

Try this link.

https://documentcloud.adobe.com/link/track?uri=urn%3Aaaid%3Ascds%3AUS%3A6dd71a6f-4931-4ab6-95cb-85abc1172753

Patrick Dees

Commercial Service Technical Team Leader

Translate
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
Community Beginner ,
Apr 15, 2019 Apr 15, 2019

Did that link work for the file?

Translate
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
Community Expert ,
Apr 15, 2019 Apr 15, 2019

Yes, and as I suspected there's a mismatch in the values. The value of "Compressor-1 Capacitor:" actually has two spaces at the end of it, which is why your code is not working.

Translate
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
Community Beginner ,
Apr 15, 2019 Apr 15, 2019

I cant believe it, wow thank you for your help.

Translate
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
Community Beginner ,
Apr 15, 2019 Apr 15, 2019

Got another one for you if you don't mind. When I have two of the same dropdown lists and rename the fields and the javascript name why do they cancel each other out and stop working.

Please see link for file.

Adobe Document Cloud

Translate
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
Community Expert ,
Apr 15, 2019 Apr 15, 2019

You use the same function SetFieldValues in both dropdown lists.

Translate
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
Community Beginner ,
Apr 16, 2019 Apr 16, 2019

So by saying in the other drop down list words rated2 and actual2 it still thinks they are the same?

What should it be changed to so that it’s different and will work?

Translate
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
Community Expert ,
Apr 16, 2019 Apr 16, 2019

You can define another function for the other field. Something like this:

function SetFieldValues2(cUnitReport)

{

  this.getField("rated2").value = UnitData[cUnitReport].rated;

  this.getField("actual2").value = UnitData[cUnitReport].actual;

}

Translate
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
Community Expert ,
Apr 16, 2019 Apr 16, 2019

Addendum: If you need to do it for more than two fields then I would use one function, but supply the field names to it as a parameter, like this:

function SetFieldValues(cUnitReport, ratedFieldName, actualFieldName)

{

  this.getField(ratedFieldName).value = UnitData[cUnitReport].rated;

  this.getField(actualFieldName).value = UnitData[cUnitReport].actual;

}

Translate
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
Community Beginner ,
Apr 16, 2019 Apr 16, 2019

The function code doesn't seem to be working, I'm certain its something I am not doing correctly.

Could you take a look and advise what needs to be changed.

The problem is nothing happens when you add the drop down choice.

Adobe Document Cloud

Translate
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
Community Expert ,
Apr 16, 2019 Apr 16, 2019

You doesn't use the function at reply 19.

Translate
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
Community Expert ,
Apr 16, 2019 Apr 16, 2019

- You don't need to re-define the data model.

- You do need to adjust the Format code of the second field, so that it uses the second function, though.

Translate
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
Community Beginner ,
Apr 16, 2019 Apr 16, 2019

Ok so to make sure I understand the data model being the whole script for getting each drop down choice is fine as it is written in SetFieldValues, correct?

Also what do the format need to be for the second field?

I tell you what when this is all said and done I need to send you a gift card to your favorite restaurant or something, thank you for all your help.

Translate
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
Community Expert ,
Apr 16, 2019 Apr 16, 2019

I've simplified the code for you. Here's the full thing (minus the details of the data model):

Doc-level script:

var UnitData = { ... };

function SetFieldValues(rateFieldName, actualFieldName) {

    if (event.willCommit) {

        if (event.value == event.target.defaultValue) {

            this.resetForm([rateFieldName, actualFieldName]);

        } else {

            this.getField(rateFieldName).value = UnitData[event.value].rated;

            this.getField(actualFieldName).value = UnitData[event.value].actual;

        }

    }

}

Custom Keystroke (not Format, sorry) script of "Motor List":

SetFieldValues("rated","actual");

Custom Keystroke script of "Motor List2":

SetFieldValues("rated2","actual2");

And I accept restaurant gift cards here. Cheers! 🙂

Translate
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
Community Beginner ,
Apr 16, 2019 Apr 16, 2019

Thanks, please note I’m not a rich man but I will certainly be sending something your way soon And if it’s okey I will more than likely have another question for you if you dont mind.

Thanks a lot you’re a pretty cool guy in my book!!!

Translate
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
Community Beginner ,
Apr 16, 2019 Apr 16, 2019

Do I copy and paste this script in place of the one I have now?

Or how would I make it work?

Translate
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