Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Where does you use the function?
Copy link to clipboard
Copied
In two fields next to the dropdown box. One called rated and the other called actual.
Copy link to clipboard
Copied
You can use the function at validation of the dropdown list.
Copy link to clipboard
Copied
How would that validation be written?
Im very new to this and need all the help I can get.
Copy link to clipboard
Copied
Also why would everything else work except the last six choices?
Copy link to clipboard
Copied
How did you call the function?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Did that link work for the file?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I cant believe it, wow thank you for your help.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
You use the same function SetFieldValues in both dropdown lists.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
You doesn't use the function at reply 19.
Copy link to clipboard
Copied
- 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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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! 🙂
Copy link to clipboard
Copied
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!!!
Copy link to clipboard
Copied
Do I copy and paste this script in place of the one I have now?
Or how would I make it work?
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more