Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
That one line should be:
for (var i=1; i<=17; i++)
Since the variable I is not the same as the variable i.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now