4 Replies Latest reply on May 30, 2012 3:09 PM by Cat286

# Creating calculation based on result of dropdown box

Hi there. I am hoping someone will be kind enough to help me with some Javascript as it seems I am too blonde and middle aged to figure it out by myself.

I have a dropdown box 'Member'. The value for Yes is 0. The value for No is 10.

Then I have three check boxes. 'Day1' value is 35. 'Day2' value is 25. 'Dinner' value is 65.

If Yes is selected, I want the sum of the check boxes if they are checked. (eg, total if all checked = 125)

If No is selected, I want the value of each check box increased by 10. (eg, total if all checked = 155)

I am using Acrobat X.

Thanks in advance.

• ###### 1. Re: Creating calculation based on result of dropdown box

Have you accounted for the situation where any one or more of the items are not selected?

Unselected check boxes have a value of "Off" and drop boxes for a blank or space value is a space.

• ###### 2. Re: Creating calculation based on result of dropdown box

Hmmm??? I think the simple answer to that is no! The drop box is a required field and can only select Yes or No. I am not sure what to do about the check boxes being off - doesn't this mean they just won't add if they are not checked?

I am a complete novice when it comes to Javascript. How I wish it was as straightforward as Excel!

1 person found this helpful
• ###### 3. Re: Creating calculation based on result of dropdown box

Because of the fact that you want to add a constant to a number of values if a given condition is meet then you will need to use a custom calculation script.

// get the value of the fields

var cMember = Number(this.getField("Member").value);

var nDay1 = this.getField("Day1").value;

var nDay2 = this.getField("Day2").value;

var nDinner = this.getField("Dinner").value;

// define a varaiable for the sum

var sum = 0;

// day 1 plus adjustement

if (nDay1 != "Off") sum += Number(nDay1) + cMember;

// day 2 plus adjustement

if ( Day2 != "Off") sum += Number(nDay2) + cMember;

// dinner plus adjustement

if (nDinner != "Off") sum += Number(nDinner) + cMember;

event.value = sum;

Excel is only easy if you accept Microsoft's view of calculations.

• ###### 4. Re: Creating calculation based on result of dropdown box

Thanks so much. I would never have got that to work without your help. May you be forever blessed with health, wealth and happiness.