Jump to content

Linking text of two combo boxes?


Yousaf

Recommended Posts

Dear Friends 

I bought Nitro Pro and got stuck on linking two separate combo boxes, so that if I select one line of text in one combo box, the second combo box automatically bring the matching value complementing to the first combo box value.

Example:

1st combo box contains:

Johnson

David

Mohammad

2nd combo box contains:

OUP_1

OUO_2

OUP_9

Now if I select Johnson in 1st box, only OUP_1 should automatically selected in the 2nd down below combo box.

I understand this question by another member had been asked but still un-answered.

Pls help?

Link to comment
Share on other sites

Dear Steven

Many thanks for helping a goof like mine.

Could you please write some steps for me to come out from this matter?

Your reply will be much appreciated for a legal Nitro customer.

Thanks in advance

 

 

Link to comment
Share on other sites

Do laymen members on this forum get neglected?

I am still waiting on my answer and I do have some justification for assistance as I paid for Nitro.

All I need from Nitro, some guided steps to make communicate two combo boxes to each other while one being sort of master and second should act passively per contents of the 1st combo box!

Is that too much to ask, Mr Steven?

If you need more money, I am ready to pay!

Link to comment
Share on other sites

  • Power User
Steven Zakulec

I'm not an employee of Nitro, and help out solely on a volunteer basis.  That being said, I'm happy to try to help out where I can.

Linking combo boxes is not something I normally do, and the linked article is quite good on how to do it.  I'm happy to point out where the equivalent Nitro options are so you can follow along with the article and make the form you need.  There's only so much I feel comfortable doing, and we're on the edge here of what I'm comfortable with since I am not a JavaScript person.

Do you have all of your combo boxes setup in your document with all the options you want already?

You'll need to do that ahead of time here.

Also, you're going to have to change the names of the fields and the values to what you want- I highly recommend looking at the finished example to see how everything ties together.

I'm including all the steps from the article as one giant quote here for convenience, and adjusting the menu & command references to be Nitro specific, but otherwise this is the same as the text from the article. 
 

Quote

 

1. You want to go to the Forms tab, and use Select Fields. 

2. Then select the master combo box, right-click on it, and choose Properties.

3. Select the Options tab.

4. We want to see the results of the user’s selection when it happens, so check the “Commit selected value immediately” option, (Figure 2). Otherwise, the selection change is not detected until the user takes the focus off the Combo Box by clicking on, or tabbing into, another field.

5. Select the Format tab.

6. From the “Select format category:” drop down list, select “Custom,” .

7. Click on the Edit button for the “Custom Keystroke Script:,” .

8. As explained earlier, the Keystroke Event is also the List Change Event. Care must be taken when using this event because it’s called twice- once when the user clicks on a list entry, and once when the data is committed. It’s the second call, when the data is committed that we want to use this event. It’s at this time that the data entry is complete and selection data is valid.

Enter the following code into “Custom Keystroke” Event script

if( event.willCommit ) {
    if(event.value == "") this.resetForm(["DeptContact","DeptEmail","DeptNumber"]); else SetFieldValues(event.value);
}

9. This code controls how the form will respond to a user selection. The first line if(event.willCommit) uses the event.willCommit property to filter out Keystroke Events caused by the user’s initial click and by actual keystrokes if the Combo Box is set up to allow text entry.

The second line if(event.value == " ") directs the script to reset a group of fields if the selection is empty. This is a little form design trick. Acrobat doesn’t allow specifying an actual empty selection, so a list entry that’s a single space character is used to represent “no selection” . When the user selects it, the fields are cleared that would otherwise be populated with some data.

For valid selections, the SetFieldValues() function is called. This is a function that we’ll be creating in the next few steps. It is this function that performs some action on the other form fields such as hiding or showing fields or changing how a calculation will be performed. In this example, the script will be pre-populating some fields.

10. Open the Document Script Dialog from:

Forms, JavaScript, Document Level
Click New
11. Enter “SetFieldValues” as the Script Name and click on the OK button.

12. Enter the following code into the script editor. Note that the SetFieldValues() function definition is already in the script. By default Acrobat creates a function with the same name as the script. In the code below this function definition has been modified with the addition of an input argument named “cDeptName “.

// Place all pre-population data into a single data structure
var DeptData = { Accounting:{ contact: "Steala Damuni", email: "accounting@mycomp.com", deptnum: "cmp1234" }, Engineering:{ contact: "Frank N. Stien", email: "engineering@mycomp.com", deptnum: "eng1234" }, Marketing :{ contact: "Shelly Oughtbuks", email: "marketing@mycomp.com", deptnum: "mkt1234" }, ITSupport:{ contact: "Goah Wei", email: "it@mycomp.com", deptnum: "its1234" }};
function SetFieldValues(cDeptName) {
    // Populate fields with values from the Department Data Object
    this.getField("DeptContact").value = DeptData[cDeptName].contact;
    this.getField("DeptEmail").value = DeptData[cDeptName].email;
    this.getField("DeptNumber").value = DeptData[cDeptName].deptnum;
}

The first part of this code is an object literal definition, DeptData, that contains all the department data, i.e., the contact names, email, and department number for each department. The data is set up all in one object to make it easy to access in code and easy to change in the future. For exactly these reasons it is good coding practice to centralize data the script will deal with whenever possible.

The data object is organized as a two level object with the department names on the first level, and all the other info in the second level. This allows access to the department info through the department name, which is exactly what’s needed since the Combo Box returns the department name.

The SetFieldValues() function applies values from the DeptData object to the appropriate fields. The specific department data is acquired from the department data object by treating the department data object as an array, for example:

DeptData[cDeptName].email;

returns the email address for the department specified by cDeptName. This “object” array notation allows the script to randomly access the department data in a simple and consistent way.

 

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.