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

Trouble Validating Drop Menu

Hangtime84
Registered: Nov 22 2011
Posts: 2
Answered

I'm trying to make my drop menu options numeric values for my cost column
 
I tried to do this boolean statement
 
If (PhotographyService1 = "Couples")
Couples = 200
 
If (PhotographyService1 = "Individual")
CostRow1 = 150
 
If (PhotographyService1 = "Family")
CostRow1 = 200
 
If (PhotographyService1 = "Event")
CostRow1 = 100
 
But went I test it out nothing happens in the CostRow1 column

My Product Information:
Acrobat Pro 10.1, Macintosh
try67
Expert
Registered: Oct 30 2008
Posts: 2398
What you can do is give each option the cost as the export value, and then use this code as the custom calculation script of your CostRow1 field:

event.value = getField("PhotographyService1").value;

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

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Accepted Answer
You have not told us where this script is located.

There are 3 options on the "Calculation" tab. There is a pick the operation and fields, the simplified field notation, and the custom calculation script. It is clearly not the first option. Simplified field notation does not accept program control statements and the syntax is not correct for accessing a field in in the custom calculation script.

I guess that "PhotographyService1" is the field name.

Have you opened the JavaScrpt Debugging console to check for errors?

As noted you can specify an export option for a drop/combo box item. If you do this, you can use the simplified field notation by just inserting the field name. This assumes all export values are unique.

If you want to use the custom calculation script then you need to acquire the field object and the value property.

For the CostRow1 field's custom calculation script:

// get the field object
var oService = this.getField("PhotographyService1");
// get the value property of the object
var nService = oService.value;

// select price for service
switch(nService) {
case "Couples":
event.value = 200;
break;

case "Individual":
event.value = 150;
break;

case "Family":
event.value = 200;
break;

case "Event":
event.value = 100;
break;

case " ":
event.value = "";
break;

// choice must be an error
default:
app.alert"Unknown Service!");
break;
} // end price setting.

Since this code will be reused with a different input value for each row, I would suggest a document level function so as to cut down on the amount of coding, but also to put the code that needs to be changed for a price change or service into one location.

The document level function:


function SetPrice(cService) {
// get the field object
var oService = this.getField(cService);
// get the value property of the object
var nService = oService.value;
// set return value
nPrice = "";
// select price for service
switch(nService) {
case "Couples":
nPrice = 200;
break;

case "Individual":
nPrice = 150;
break;

case "Family":
nPrice = 200;
break;

case "Event":
nPrice = 100;
break;

case " ":
// doe nothing
break;

// choice must be an error
default:
app.alert"Unknown Service!");
break;
} // end price setting.

// return price
return nPrice;
} // end function

The custom calculation script for CostRow1"


// get the field object
var oService = this.getField("PhotographyService1");
// get the value property of the object
var nService = oService.value;
event.value = SetPrice(nService);

You only need to change one line of code for each row. It is even possible to have the script calculate the row name so one does not even need to change any code in the calculation script.

George Kaiser

Hangtime84
Registered: Nov 22 2011
Posts: 2
Thank You very much it worked perfectly I didn't even think of creating a case statements


Question Could the same process work with radio buttons