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

Community Beginner ,
Dec 23, 2019 Dec 23, 2019

Copy link to clipboard

Copied

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.

 

TOPICS
Acrobat SDK and JavaScript, Create PDFs, How to, PDF forms

Views

692

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Dec 24, 2019 Dec 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. 

Likes

Translate

Translate
Adobe Community Professional ,
Dec 23, 2019 Dec 23, 2019

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 24, 2019 Dec 24, 2019

Copy link to clipboard

Copied

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)

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 24, 2019 Dec 24, 2019

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 24, 2019 Dec 24, 2019

Copy link to clipboard

Copied

LATEST

Ugh. Yes, I did and checked that it was gone. However, I must have had an undo in the interim that undid my delete at that spot too. I re-deleted it and it is now working. Thanks very much!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines