Copy link to clipboard
Copied
I'm trying to create a field that is automatically populated if a specific selection is made in a listbox. If that specific selection is NOT in the listbox then I want to be able to manually add text in that field.
See below. If I select AVLEASE, FJAUDILEASE or FJMBLEASE in the listbox, I want a field to populate with the word LEASE. If any other selection is made in my listbox, I want to be able to manually enter text into this field.
I'm using the Custom calcuation script box in the text field properties calculate tab.
This is what I have and it dosen't work. I cannot manually enter text in that field:
var v = this.getField("LISTBOXDEALER").valueAsString;
if (v=="AVLEASE") event.value = "LEASE";
else if (v=="FJAUDILEASE") event.value = "LEASE";
else if (v=="FJMBLEASE") event.value = "LEASE";
else event.value = "";
event.rc = (v != ""); // this blocks the calc
event.target.readonly = event.rc // This blocks or enables user data entry
Copy link to clipboard
Copied
The calculate script isn't working for a couple of reasons.
First, "v" is never an empty string, so event.rc is never set to false and readonly is always true.
Second, both setting event.rc to false and setting the field value to a blank are not possible, because setting event.rc to false tells the JS engine to ignore event.value.
This type of action is better done in the "Select Change" script of the listbox.
Also make sure the "Commit selected value immediately" option is checked.
Here's the select change script:
var oTgtFld = this.getField("textbox");
if ((event.value=="AVLEASE") || (event.value=="FJAUDILEASE") ||(event.value=="FJMBLEASE"))
{
oTgtFld.value = "LEASE";
oTgtFld.readonly = true;
}
else
{
oTgtFld.value = "";
oTgtFld.readonly = false;
}
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
To be more clear, I want a textbox to be populated with the result of specific entries in a listbox. If one of those entrites in NOT selected then I want to be able to manually enter text in the textbox. In my example if I select one of the three leases, then I want the word LEASE to appear in the text box. If I choose one of the three other options, then I want to be able to manually enter text in the textbox. With my current script, as soon as I tab off the textbox after entering anything, the text disappears.
Copy link to clipboard
Copied
The calculate script isn't working for a couple of reasons.
First, "v" is never an empty string, so event.rc is never set to false and readonly is always true.
Second, both setting event.rc to false and setting the field value to a blank are not possible, because setting event.rc to false tells the JS engine to ignore event.value.
This type of action is better done in the "Select Change" script of the listbox.
Also make sure the "Commit selected value immediately" option is checked.
Here's the select change script:
var oTgtFld = this.getField("textbox");
if ((event.value=="AVLEASE") || (event.value=="FJAUDILEASE") ||(event.value=="FJMBLEASE"))
{
oTgtFld.value = "LEASE";
oTgtFld.readonly = true;
}
else
{
oTgtFld.value = "";
oTgtFld.readonly = false;
}
Use the Acrobat JavaScript Reference early and often

