Copy link to clipboard
Copied
I have a series of dropdowns that I want to attach the same script to that basically makes a "notes" textfield required if the dropdown value is "fail" (and makes it not required if it is "pass"). The script I have for one of the dropdowns is:
var result = this.getField("Dropdown5");
var notes = this.getField("Text14");
if(result.value == "Fail"){
notes.required = true;
}else{
notes.required = false;
}
on mouse exit and it works fine but I was wondering if there is some other way to reference the dropdown that the script is attached to besides using the name. I know this refers to the pdf, but is there some other javascript construct or something to refer to the currently attached field? This way I won't have to edit a bunch of different scripts just to change the name and I can just do a copy/paste. OR is there some way to do this with a document script? I tried making one but nothing happened when I changed any dropdowns.
You can refer to the field using this code: event.target
Copy link to clipboard
Copied
One can define a function in JavaScript. This function is like the function in mathematics in that you have parameters that provide the values to be processed or in this case the field names to be processed. If there is some type of systemic construct for naming the fields, it is possible to compute the names of the fields to be processed.
Copy link to clipboard
Copied
So your answer to my very specific question about how to refer to a field by not using it's name is to be as vague and cryptic as possible? Thanks for your help. I totally understand what I need to change in my code now just from your comment /s
Copy link to clipboard
Copied
I would start by making 2 fields. A drop down box named "Dropdown" and a text field named "Text". The drop down box would have the option "Commit selected value immediately" selected, The options for the field would have entries like " ", "Pass", "Fail". The field would have a "Format" using the "Custom" option and a key stroke script of:
var cName = event.targetName;
var aName = event.targetName.split(".");
var oText = this.getField("Text." + aName[1]);
if(event.willCommit == false)
{
oText.required = false;
oText.value = event.changeEx;
if(event.changeEx == "Fail")
{
oText.required = true;
} // end cangeEx "Fail";
} // end willCommit;
I would then select both fields and use the right mouse context menu option "Create Multiple Copies" and create 5 down and 1 across. Then exit the "Prepare Forms" mode and test the form. Note this approach will work for any number of fields more than one.
Copy link to clipboard
Copied
You can refer to the field using this code: event.target
Copy link to clipboard
Copied
Here's an article on Dropdown/list field programming:
https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm