Skip to main content
Participating Frequently
December 23, 2019
Answered

Trying To Populate a Text Box with Export Values from Multiple Selections from a Dropdown List Box

  • December 23, 2019
  • 1 reply
  • 3026 views

Hello,

I am trying to poplulate a textbox with the export values from multiple selections from a Dropdown List Box. For example, my dropdown list box may have:

 

Item Value/Export Value:

Posting Journal Entries to General Ledger/F_GL_POST

Budget Adjustment Entry/F_BD_ENTRY

etc.

 

I want the user to pick from the descriptive terms (the Item Value in the Dropdown list), but have the more technical description (the Export Value) poplulate in the text box. The user picks as many Item Values as they need one at a time. If they pick one they don't need, they pick it again and it is removed from their selections. I found a DOCUMENT LEVEL script online that works for this EXCEPT that it provides the Item Values rather than the Export Values. I need the Export Values in the text box, not the Item Values.

 

Here is the script:

function fillRoles(doc, fieldName, newValue)
{
    var ar = [];
    // Get the value(s) currently stored in the dropdown value and 
    // convert them to an array
    var v = doc.getField(fieldName).value;
    if (v.length > 0) {
        var ar = v.split(",");
    }
    // Do we already have newValue in the array? 
    var foundIt = -1;
    for (var i=0; i<ar.length; i++) {
        if (ar[i] == newValue) {
            foundIt = i;
            break;
        }
    }
    if (foundIt != -1) {
        // remove the item
        ar.splice(i, 1);
    }
    else { // add the item at the end
        ar.push(newValue);
    }
    // convert the array to a string
    this.getField(fieldName).value = ar.join();
}

 After I added the document level script, I added the following code to the dropdown list on the Validate tab under the 'Run Custom validation script':

fillRoles(this, "textbox name here", event.value);

I am trying to figure out what I need to change to display the export values rather than the Item values.

 

Thank you.

 

This topic has been closed for replies.
Correct answer Thom Parker

Did you remove the validation script?

The only way the item value could be there is if the other script was also being run. So get rid of it. 

1 reply

Thom Parker
Community Expert
Community Expert
December 23, 2019

You can read everything you need to know to solve this issue in the Acrobat JavaScript Reference, and in the articles posted here:

https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm

 

Given the material at these sites, there is a simple and obvious solution. Delete the code in the validation Script, and then add this line to a custom Keystroke script on the Dropdown.

 

if(!event.willCommit) fillRoles(this, "textbox name here", event.changeEx);

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
melb2Author
Participating Frequently
December 24, 2019

OK, thank you. I've  made the change that you suggested. However, now the results in the textbox are BOTH the Item Value and the Export Value.

 

For example,

F_GL_POST,Posting Journal Entries to General Ledger,F_BD_ENTRY,Budget Adjustment Entry

 

What I need is:

F_GL_POST, F_BD_ENTRY  (hopefully with a comma and a space like this, not just a comma)

 

 

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
December 24, 2019

Did you remove the validation script?

The only way the item value could be there is if the other script was also being run. So get rid of it. 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often