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

Having trouble with code

jkon13
Registered: Sep 30 2008
Posts: 6

I have a drop down box in a form field and based on the selection within that drop down box another form field is multiplied by a number determined by the drop down box selection. I hope that explains it well enough. I'm not experienced at all with javascript so I might way off.

Here is the code that I have written.

if (ComboBox2 == weekly){
MonthlyNetIncomeSalaryWagesSelf == NetPerCheckSalaryWagesSelf * 4.2;
} else if
(ComboBox2 == bi-weekly){
MonthlyNetIncomeSalaryWagesSelf == NetPerCheckSalaryWagesSelf * 2.1;
} else if
(ComboBox2 == monthly){
MonthlyNetIncomeSalaryWagesSelf == NetPerCheckSalaryWagesSelf * 1;
}

Any help would be much appreciated.

My Product Information:
Acrobat Pro Extended 9.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Did you create the form fields in Acrobat or LiveCycle Designer? Where (what field, what event) did you place that code above? Are those three values (weekly, bi-weekly, monthly) the export values of your combo box items? Is "Combobox2" the name of your combobox field? Is "NetPerCheckSalaryWagesSelf" the name of another field on your form? If so, what type of field? What about "MonthlyNetIncomSalarayWagesSelf"? Is it the name of the calculated field?

In other words, the more details you provide the better.

George
jkon13
Registered: Sep 30 2008
Posts: 6
I created the form fields in Acrobat 9 Pro Extended. I placed the code in the form field MonthlyNetIncomSalarayWagesSelf, which is the calculated field. Combobox2 is the field with the comboboxes and the three values are the choices in combobox2. NetPerCheckSalaryWagesSelf is another form field that has a number value in it that will be calculated by another value that is determined by the option selected in the combobox. The number value that is in NetPerCheckSalaryWagesSelf is entered by the person filling out the form. The Javascript editor accepts my code it just does not calculate it within the form.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Much better! Here is some code that I hope will get you pointed in the right direction. It is intended to be placed as the custom calculation script of the MonthlyNetIncomeSalaryWagesSelf field:

// Get the value of the combo boxvar s1 = getField("Combobox2").value; // Get the value of the numeric fieldvar n1 = getField("NetPerCheckSalaryWagesSelf").value; // Calculate and set the value of this fieldif (n1 !== "") { switch (s1) { case "weekly":event.value = n1 * 4.2;break; case "bi-weekly":event.value = n1 * 2.1break; case "monthly":event.value = n1;break; default: }} else {event.value = "";}

This code makes a number of assumptions, such as you want the field to be blank if there is not entry in the NetPerCheckSalaryWagesSelf field, but it should get you started.

This code could also be improved a number of ways. First, it could check the value of n1 to make sure it makes sense for this application (is not negative, is not too large, etc.) and doesn't unnecessarily create those global variables. Also, the code could be simplified and less prone to bugs if you were to specify the multipliers (4.2, 2.1, 1) as the export values of the combo box items. For example:

(function () { // Get the value of the combo box// It will be either 4.2, 2.1, or 1var n1 = getField("Combobox2").value; // Get the value of the numeric field// Assume it is numeric or emptyvar n2 = getField("NetPerCheckSalaryWagesSelf").value; // Calculate and set the value of this fieldif (n2 !== "") {event.value = n1 * n2;} else {event.value = "";} })();

You could validate the value of the NetPerCheckSalaryWagesSelf field in its Validate event. Post again if you'd like some suggestions, and include the range of valid values for this field.

George