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

Script Syntax

New Here ,
Jul 11, 2016 Jul 11, 2016

I have this code where I would like to change the criteria.  Right now it reads that if a particular field is filled in, then a range of fields will be added together
(see below).  How do I change it so that it looks for a dropdown response before performing the calculation?

if (this.getField("Date").valueAsString==""") event.value = "";

   else {

      var total = 0;

      for (var I=1; I<=17; i++)

          total+=Number(this.getField("Text"+i).value);

      event.value = total;

   }

TOPICS
Acrobat SDK and JavaScript , Windows
359
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
LEGEND ,
Jul 11, 2016 Jul 11, 2016

You test the value of the drop down field and then execute the desired block of code. The value of the drop down box will be limited to the entries in the drop down list unless you allow users to add new items.

You can find more out about JavaScript syntax for fee with

MDN JavaScript Reference for core JavaScript

and Acrobat JavaScript API Reference for Acrobat specific objects.

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
LEGEND ,
Jul 11, 2016 Jul 11, 2016

That one line should be:

for (var i=1; i<=17; i++)

Since the variable I is not the same as the variable i.

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 ,
Jul 12, 2016 Jul 12, 2016

Thank you George.  Windows must've capitalized the "i" on it's own and I did not realize it.  I was looking through JavaScript Reference that gkaiseril posted, and I still have questions about the actual language (syntax) needed to look at the Dropdown.  I tried replacing the "Date" with the name of the Dropdown box, but it is still automatically totaling the field.

Thanks for all your help.

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
LEGEND ,
Jul 12, 2016 Jul 12, 2016
LATEST

What you need to do is determine what the value of the dropdown is when you don't consider it to be filled-in. People will often include a list item that is simply a single space so it appears blank, or something like "Please select". If you have something like this, your script would check for it and perform the calculation accordingly.

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