calculation with dropdown

3
Replies Cat286 Creating calculation based on result of dropdown box May 30, 2012 2:48 AM Categories: Windows 466 Views 4 Replies Latest reply: Cat286, May 30, 2012 3:09 PM 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. GKaiseril, May 30, 2012 8:24 AM in reply to Cat286 Report 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.

Upload: kenthepa

Post on 13-Apr-2015

7 views

Category:

Documents


0 download

DESCRIPTION

JavaScript for adobe acrobat forms. Change other field with drop down selection

TRANSCRIPT

Page 1: Calculation With Dropdown

Replies

Cat286

Creating calculation based on result of dropdown boxMay 30, 2012 2:48 AMCategories: Windows

466 Views 4 Replies Latest reply: Cat286, May 30, 2012 3:09 PM

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. GKaiseril,

May 30, 2012 8:24 AM in reply to Cat286Report

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.

Page 2: Calculation With Dropdown

|Mark as:

2. Cat286,

May 30, 2012 1:51 PM in reply to GKaiserilReport

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!

|Mark as:

3. GKaiseril,

May 30, 2012 2:42 PM in reply to Cat286Report

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 fieldsvar 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 sumvar sum = 0;// day 1 plus adjustementif (nDay1 != "Off") sum += Number(nDay1) + cMember;// day 2 plus adjustementif ( Day2 != "Off") sum += Number(nDay2) + cMember;// dinner plus adjustementif (nDinner != "Off") sum += Number(nDinner) + cMember;event.value = sum;

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

|

Page 3: Calculation With Dropdown

Adobe Community powered by Jive SBS ® 4.5.6.3 forum software © Jive Software

4. Cat286,

May 30, 2012 3:09 PM in reply to GKaiserilReport

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

|Mark as: