Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript calculation

New Here ,
Feb 25, 2018 Feb 25, 2018

So here's the deal I need to write a javascript that displays a number in a text box based on which checkbox is checked so basically:

Text box 1 must display a number from one of the following lines depending on which Checkbox is Checked

The numbers are for reference only and would be whatever the user entered in that field.

(Checkbox 1)  16

(Checkbox 2)  21

(Checkbox 3)  3

(Checkbox 4)  7

If there is a video or something that can be referenced I'm super new to this and appreciate the education

TOPICS
Acrobat SDK and JavaScript , Windows
213
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 25, 2018 Feb 25, 2018

Do you mean that there's a text field next to each check-box, and if that box is ticked the value of the text field should appear in another text field? What if more than one box is ticked? What are the names of the fields involved?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2018 Feb 25, 2018

try67​

Do you mean that there's a text field next to each check-box: Yes

if that box is ticked the value of the text field should appear in another text field: Yes

What if more than one box is ticked? It would be additive

What are the names of the fields involved?  form fields.png

The Worn fields are named Worn.1, Worn.2 and so on. The Fields AT1.0 to AT1.7 are not relevant (just for notes) AV1.0 to AV1.7 are the fields i want to associate with the check boxes. Sort of "IF Worn.1 is checked then add AV1.0 to AC"

AC is the text box (not in the picture) where the totals would populate. AV fields are numbers only. Thanks for your reply and i really value your assistance

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 25, 2018 Feb 25, 2018
LATEST

OK. Use this code as the custom calculation script of the total field:

var total = 0;

for (var i=0; i<=7; i++) {

    if (this.getField("Worn."+i).valueAsString!="Off")

        total+=Number(this.getField("AV1."+i).valueAsString);

}

event.value = total;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines