Copy link to clipboard
Copied
Hello Adobe Community Brains Trust,
I am currently using Adobe Acrobat DC Pro 2015 and am a complete javascript noob!
I am trying to create a fillable PDF client order form - there is a drop-down field called Nutrition Product (20 items) and another field called Nutrition Product code, and I want to set the following action:
- If Product 1 is selected in the Nutrition Product drop-down list, Product 1 code will automatically populate in the Nutrition Product Code field, and so on..
For each of the products in the drop- down list, I have included the product code in the Export Value field in the Options tab.
I have read a few articles and tried the below javascript code in the Nutrition Product field, however the Nutrition product code field is not auto-populating with the code number. Where am I going wrong? Any advice would be gratefully received. Many thanks TJ 😊
if(event.value == "Ensure Powder Vanilla 850g can"){
this.getField("Nutrition_Product_Code").value = "S619.185";}
else if(event.value == "Ensure Powder Chocolate 850g "){
this.getField("Nutrition_Product_Code ").value = "S620.185";}
else {
this.getField("Nutrition_Product_Code").value = "";}
Copy link to clipboard
Copied
If you set export value, then use this as custom calculation script of Nutrition Product code field:
event.value = this.getField("Nutrition Product").value;
Copy link to clipboard
Copied
The console.println() should be placed at the top of the script.
Like this.
console.println("Selected:" + event.value + ":");
Every time a selection is made, the value seen by the script will be printed to the console window. You can then match these values against the ones used in the script.
The reported error is from code run in the console window. I'd ignore it for now and work on making sure the selected values match the code.
Looks like you are on the way to a working script.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
On the face of it your code looks good. But there are several things that can go wrong.
1) Where is this code placed? It should be in the validation script for the dropdown
2) The dropdown "commit selected value immediately" option should be set.
3) Are you sur about the values? Use a console.println() statement in the code to ensure you are using the correct ones.
4) Did you check the console window for errors?
5) There are two errors in the code. Both are extra spaces inside quotes.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thanks for your reply Thom! Please see my responses below:
1) Yes, the code is placed in the Validation script in the dropdown
2) Yes, this box has been ticked
3) The product codes are the supplier's codes (the order is sent to 3rd party supplier). Oh, where abouts do i include the console.println() statement in the code?
4) I just looked up your article on how to do this 🙂 i entered the code in this window and it came up with the following error message:
SyntaxError: syntax error
1:Console:Exec
undefined
What does this mean please?
5) Thank you for the pick up, i have removed the extra spaces!
Many thanks for your help Thom 🙂 TJ
Copy link to clipboard
Copied
The console.println() should be placed at the top of the script.
Like this.
console.println("Selected:" + event.value + ":");
Every time a selection is made, the value seen by the script will be printed to the console window. You can then match these values against the ones used in the script.
The reported error is from code run in the console window. I'd ignore it for now and work on making sure the selected values match the code.
Looks like you are on the way to a working script.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Absolute wizard, this worked! Thanks so much 🙂 TJ
Copy link to clipboard
Copied
If you set export value, then use this as custom calculation script of Nutrition Product code field:
event.value = this.getField("Nutrition Product").value;
Copy link to clipboard
Copied
Thank you so much for your reply Nesa 🙂 This seems like a much simpler code! I'm going to give this a go as I have another 6 set of product categories with >100 product items!
Copy link to clipboard
Copied
You have an extra space at the end of the field name in this line:
this.getField("Nutrition_Product_Code ").value = "S620.185";}
Copy link to clipboard
Copied
This is very similar to what I am trying to achieve, I think. I am VERY new to this.
I have a form with a drop down field labeled "Wreckers". Below this field is where their address will be. I would like the "address" text box to automatically populate the address for any of the options in the drop down list.
I hope I have given enough information or ever worded this in a manner that can be understood.
Thank you!!

