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

Can't get Javascript to auto-populate text fields correctly

clotte
Registered: Feb 14 2008
Posts: 9

I wrote a post yesterday asking how to do this. I received a reply sending me to this article written by Thom Parker:
http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/change_another_field/

i have followed the directions, and i do not receive any errors, however when i try it out in my pdf doc, it does not work.

Here's my code:

var DegreeData = { "Astronomy and Astrophysics":{ tuition: "$36,666",
activitiesfee: "$135",
healthservicefee: "$504",
tuitionsubtotal: "$37,305",
healthinsurance: "$1,770",
books: "$1,740",
livingexpenses: "$14,130",
other: "$4,170",
livingexpensessubtotal: "$21,810" },
"Biological Sciences Division":{ tuition: "$46,596",
activitiesfee: "$135",
healthservicefee: "$672",
tuitionsubtotal: "$47,403",
healthinsurance: "$1,770",
books: "$1,740",
livingexpenses: "$18,840",
other: "$0",
livingexpensessubtotal: "$69,753" }};

function SetFieldValues(cDegreeProgram)
{
this.getField("Tuition").value = DegreeData["Astronomy and Astrophysics"].tuition;
this.getField("Activities Fee").value = DegreeData["Astronomy and Astrophysics"].activitiesfee;
this.getField("Health Service Fee").value = DegreeData["Astronomy and Astrophysics"].healthservicefee;
this.getField("Tuition Subtotal").value = DegreeData["Astronomy and Astrophysics"].tuitionsubtotal;
this.getField("Health Insurance").value = DegreeData["Astronomy and Astrophysics"].healthinsurance;
this.getField("Books").value = DegreeData["Astronomy and Astrophysics"].books;
this.getField("Living Expenses").value = DegreeData["Astronomy and Astrophysics"].livingexpenses;
this.getField("Other").value = DegreeData["Astronomy and Astrophysics"].other;
this.getField("Living Expenses Subtotal").value = DegreeData["Astronomy and Astrophysics"].livingexpensessubtotal;

this.getField("Tuition").value = DegreeData["Biological Sciences Division"].tuition;
this.getField("Activities Fee").value = DegreeData["Biological Sciences Division"].activitiesfee;
this.getField("Health Service Fee").value = DegreeData["Biological Sciences Division"].healthservicefee;
this.getField("Tuition Subtotal").value = DegreeData["Biological Sciences Division"].tuitionsubtotal;
this.getField("Health Insurance").value = DegreeData["Biological Sciences Division"].healthinsurance;
this.getField("Books").value = DegreeData["Biological Sciences Division"].books;
this.getField("Living Expenses").value = DegreeData["Biological Sciences Division"].livingexpenses;
this.getField("Other").value = DegreeData["Biological Sciences Division"].other;
this.getField("Living Expenses Subtotal").value = DegreeData["Biological Sciences Division"].livingexpensessubtotal;
}

I'm trying to have the selection "Astronomy and Astrophysics" - or whatever other degree program to autopopulate text fields: Tuition, Activities Fee, etc. Currently in my document, it only displays the data for Biological Sciences Division even when i am choosing Astronomy and Astrophysics.

Please HELP!
I am willing to send my pdf doc so you can see if (send me an email address).

Thanks,
Christine

My Product Information:
Acrobat Pro 8.0, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Very carefully review Thom's code and your code. Note that the "SetFieldValues" function has a passed parameter called "cDegreeProgram". The value of this parameter is used to select the correct element from the "DegreeProgram" data object and the assciate parts of that element.

It appears that you will be populating the various fields based on the selection from a drop down or combo box, so in the "Custom key stroke" your code should read:
function SetFieldValues(cDegreeProgram) {// populate fields with the the values for of the cDegreeProgram element in the DegreeProgram objectthis.getField("Tuition").value = DegreeData[cDegreeProgram].tuition;this.getField("Activities Fee").value = DegreeData[cDegreeProgram].activitiesfee;this.getField("Health Service Fee").value = DegreeData[cDegreeProgram].healthservicefee;this.getField("Tuition Subtotal").value = DegreeData[cDegreeProgram].tuitionsubtotal;this.getField("Health Insurance").value = DegreeData[cDegreeProgram].healthinsurance;this.getField("Books").value = DegreeData[cDegreeProgram].books;this.getField("Living Expenses").value = DegreeData[cDegreeProgram].livingexpenses;this.getField("Other").value = DegreeData[cDegreeProgram].other;this.getField("Living Expenses Subtotal").value = DegreeData[cDegreeProgram].livingexpensessubtotal;return; // end funciton}

Then for the drop down/combo box the custom keystroke code should be:

if( event.willCommit ) // when selection is made{if(event.value == "") // if event not the default valuethis.resetForm(["Tuition", "Activities Fee", "Health Service Fee", "Tuition Subtotal", "Health Insurance", "Books", "Living Expenses", "Other", "Living Expenses Subtotal"]); // clear the fieldselseSetFieldValues(event.value); // set the fields for the selected degree program}

George Kaiser