Copy link to clipboard
Copied
Hello. I am trying to script 2 to 3 comboboxes. The first box would have multiple choices of types of pipe threads I make and each successive combo box would be narrowed by the previous choice.
I feel there is some type of security issue or I am not running the code correctly. The code works as it should and then it does not. Just looking for some pointers. I am using Acrobat dc and have javascript enabled. Here is an example of what I am struggling with. I will be adding more switch statements with if conditions. The reason I think my setup is the problem is because I have followed tutorials to the T and am not getting the output I expect or any at times, no errors just nothing. Should I not be checking for functionality with "preview"? I believe I am working with an interactive pdf.
Any advice is appreciated Thanks
var threadType = this.getField("Dropdownbox1");
var threadDiameter = this.getField("Dropdownbox2");
var weightPerFoot = this.getField(Dropdownbox3);
if (event.willCommit)
switch (event.value) {
case "Blue":
threadDiameter.setItems["2.375", "2.875", "3.50", "4.50", "5.50", "7.00", "9.625"];
break;
}
Copy link to clipboard
Copied
What output does you expect?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Where did you place the code? Can you share the file?
Copy link to clipboard
Copied
I have been putting it my code in the Dropdownbox1 Custom Key Script. Here is a rough idea of where I am. I havent moved forward because I havent been able to get consistant results yet with where I am.
It seems like One Drive keeps messing up all my file locations and permissions. I wonder if that is affecting the functionality.
Copy link to clipboard
Copied
When you're testing a PDF form it's vital to open the JavaScript console. It won't pop up a box telling you there is an error in your script, it all goes to the console. When I choose Blue the console says "TypeError: threadDiameter is null -- 5:AcroForm:Dropdown1:Keystroke"
Copy link to clipboard
Copied
Thank you for taking the time to reply. Would the proper way to test the code be to make code changes then close out combobox wizard, then save file, then enter the "JavaScript" acrobat workspace and instantiate code via. Debugger button.
I am getting the same error "TypeError: threadDiameter is null".
Copy link to clipboard
Copied
I'm not entirely sure what the Combobox wizard is, I've never used it, and I don't recognise a JavaScript workspace, just a window. But when I'm using form tools...
1. I keep the JavaScript console open full time - though it can be closed if there isn't room on screen.
2. I exit Prepare Form using the Close button on the toolbar.
The error is giving you the line number with the error. In this case the error can be traced to one of the lines above, you are using getField with the wrong field names. So nothing else will work. However, using getField with the wrong field name doesn't give an error at the time - it is documented that it returns null in this case. The actual error detected is trying to do something with that null value. Careful programmers will add a check after each line that might fail, but it's a lot more work.
Copy link to clipboard
Copied
The proper way to test this kind of code is to use it. If the code is triggered by changing the value of a drop-down field, then change the field's value, and then see if there are any errors in the JS Console, and if not, whether the code does what you expect it to do.
Copy link to clipboard
Copied
You use:
var threadType = this.getField("Dropdownbox1");
var threadDiameter = this.getField("Dropdownbox2");
var weightPerFoot = this.getField("Dropdownbox3");
There doesn't exists any field with this names.
Copy link to clipboard
Copied
As noted by the other posters, your first issue is that the field names are incorrect.
Next, and this is a trivial point, there is no reason to get the field object for the field the script is operating in, i.e. "Dropdown1". Since this field is the target of the script, it's field object is "event.target".
Next, all of the fields need the "Commit selected value immediately" option checked. Then you can use the "Commit" event.
And finally, change how this line is used
if (event.changeEx!=0) threadDiameter.insertItemAt("- Thread Diameter -", 0);
Here's a quick rewrite of the code (it assumes that the commit option is checked):
var threadDiameter = this.getField("Dropdown2");
if (event.willCommit) {
if(!event.value || (event.value == ""))
threadDiameter.setItems(["- Thread Diameter -"]);
else{
switch (event.value) {
case "Blue":
threadDiameter.setItems(["2.375", "2.875", "3.50", "4.50", "5.50", "7.00", "9.625"]);
break;
case "563":
threadDiameter.setItems(["2.875", "3.50", "4.50", "5.50", "6.00", "7.625"]);
break;
// etc.
}
}
}
Copy link to clipboard
Copied
Hi,
If I understood correctly, place this script in custom keystroke script of the Dropdownbox1 field:
var threadType = this.getField("Dropdownbox1");
var threadDiameter = this.getField("Dropdownbox2");
var weightPerFoot = this.getField("Dropdownbox3");
if (!event.willCommit) {
threadDiameter.clearItems();
switch (event.changeEx) {
case "Blue":
threadDiameter.setItems(["2.375", "2.875", "3.50", "4.50", "5.50", "7.00", "9.625"]);
break;
case "Red":
threadDiameter.setItems(["1.375", "2.875", "3.50", "4.50", "5.50", "6.00", "7.625"]);
break;
// etc.
}
if (event.changeEx!=0) threadDiameter.insertItemAt("- Thread Diameter -", 0);
}
@+
Copy link to clipboard
Copied
Thank you. I am not having succsess with the code installed in "custom key script" DropdownBox1.
I noticed the file and some parent files were read only and they keep being saved in some onedrive folder. It seems like this may be part of my problem. I am now right clicking and changing file to "Always Keep on This Device". Still not getting desired outcome. Thanks
Copy link to clipboard
Copied