These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Text boxes populated by multiple dropdowns

DustinH
Registered: Jun 22 2011
Posts: 6
Answered

I posted this last week, but it seemed to disappear. If it was removed, please let me know if there is another place I should be asking about this.
 
I'm a complete novice to JavaScript and have complied what I can from what I've found on this forum so far. I almost have my script working, but I'm missing something. Using Acrobat X Pro.

Basically, the form is meant to pick a department from one drop down, a position from another, and that position will populate the two text fields with required equipment and accounts (form for tracking employee equipment and accounts).

To achieve this, I created one drop down with all the departments, and have separate dropdowns for each department to select the positions. I originally tried to have the department dropdown populate a single dropdown with that departments specific positions. I got that to work, but couldn't figure out how to then make the position one populate the text boxes.

So what I have now is a drop down for each department which contains the positions and just hide / show them based on the department selected. I then used a script to populate the text boxes based on the position selection, which is working.

My problem is I can't get multiple departments to work. The script will allow a single dropdown to populate the text fields, and the others do nothing.

Here is the script I'm using with only 2 departments (haven't added more since I can't get the two working). Right now, this scrip will populate the Admin and InformationSystems dropdowns with the correct position. The admin one will populate the text fields EquipText and AccountText as intended, but the InfoSys one will not populate the text boxes at all.

I really really appreciate any help anyone can give!

//*****************************************************************************************
//ADMIN

//First make the values for Admin Department.

myAdminValues = ["", "CEO", "CFO", "Assistant"];

//Then populate the values to Admin Department.

this.getField("Admin").setItems(myAdminValues);

// Then you define what has to be shown in textboxes when value is selected

var AdminData = { CEO:{ equip: "Blackberry" ,
account: "Raiser's Edge, Crossnet, ProxCard" },
CFO:{ equip: "Laptop, Blackberry, Keys, ProxCard, ADP",
account: "Raiser's Edge, ISIS, Crossnet" } ,
Assistant :{ equip: "Laptop, Blackberry",
account: "Raiser's Edge, Crossnet, CEO Email" }
};

//Finally set the values of the textboxes

function SetFieldValues(cDeptName2)

{

this.getField("EquipText").value = AdminData[cDeptName2].equip;
this.getField("AccountText").value = AdminData[cDeptName2].account;
}

//*****************************************************************************************
//INFORMATION SYSTEMS

//First make the values for Infosys Department.

myInfoSysValues = ["", "Manager", "Coordinator", "Associate"];

//Then populate the values to Infosys Department.

this.getField("InformationSystems").setItems(myInfoSysValues);

// Then define what has to be shown in the textboxes when value is selected

var InfoSysData = { Manager:{ equip: "Laptop, Blackberry" ,
account: "Raiser's Edge, ISIS, Extranet, Crossnet" },
Coordinator:{ equip: "Laptop, Blackberry, Keys",
account: "Raiser's Edge, ISIS, Extranet, Crossnet" } ,
Associate :{ equip: "Laptop",
account: "Raiser's Edge, ISIS, Extranet, Crossnet" }
};

//set the values of the textboxes

function SetFieldValues(cDeptName1)

{

this.getField("EquipText").value = InfoSysData[cDeptName1].equip;
this.getField("AccountText").value = InfoSysData[cDeptName1].account;
}

My Product Information:
Acrobat Pro, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You are defining two functions with the same name. That should cause an error.
Are there any errors in the JS console?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

DTjava
Registered: Jun 17 2011
Posts: 21
Hi DustinH,

I had a similar project - Instead of dropdowns, I was using checkboxes. George helped me out in a previous post...it works as is, but it can be pretty daunting to a new user, and it includes both document and form level javascript. But it does work!

Good luck:

http://acrobatusers.com/forum/javascript/populating-text-field-multiple-checkbox-inputs
DustinH
Registered: Jun 22 2011
Posts: 6
try67 wrote:
You are defining two functions with the same name. That should cause an error.
Are there any errors in the JS console?
Never even thought to check. Here's what it is giving me.

TypeError: InfoSysData[cDeptName1] is undefined
59:AcroForm:Admin:Keystroke



Which is interesting to me because the InfoSys section is working, and the Admin section is not working.

I think I realize the issue of having two functions 'SetFieldValues' - I'm not sure how to accomplish what I need though.

It is giving these errors when I have the Admin dropdown selected and click on the positions for it. When I make selections from the InfoSys department, it works and there are no errors.





DTjava - I saw that post before, but I haven't a clue how to modify it for my needs. I don't think I need something as complex as I'm not adding different items to the text boxes, just data from a single dropdown selection. While the idea's are similar, I believe the scripting needed to be much different with the use of dropdowns.



DustinH
Registered: Jun 22 2011
Posts: 6
Here is where I got a lot of my code: http://acrobatusers.com/tutorials/2006/change_another_field

The problem is that I'm using multiple dropdowns instead of one, and not sure how to get the code and separate data to apply to each different dropdown.

It is similar to this question, but it never got an answer.

http://acrobatusers.com/forum/forms-acrobat/combo-boxes
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Try printing out cDeptName1 to the console, to make sure it has the value you're expecting.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

DustinH
Registered: Jun 22 2011
Posts: 6
Accepted Answer
I was able to figure out the issue.

The problem was the same function name so thanks for pointing that out. I changed it to SetFieldValue and SetFieldValue1. My disconnect was that I needed to make those same changes at the custom keystroke scripts for each dropdown.

I was using this custome keystroke script for every dropdown:



if( event.willCommit )
{
if(event.value == "-")
this.resetForm(["EquipText"]),
this.resetForm(["AccountText"]);

else
SetFieldValues(event.value);
}



By changing SetFieldValues to SetFieldValues1 for informationsystems, and also changing it to SetFieldValues1 in the document level script for informationsystems, the form works as intended.


Thanks for all the help guys, you all rock!