Skip to main content
CourtnessJames
Participant
March 13, 2017
Answered

How can I calculate how many text drop down fields contain an "S" in a form?

  • March 13, 2017
  • 1 reply
  • 775 views

I have fields numbered 1-83.  In each of these fields people can choose an S, NI, or U.  I'd like to enter a calculation in field total S, total NI, total U that will count how many of each these employee received.

What is the suggested calculation and where do I enter it?

Thank you in advance for your brilliance.

This topic has been closed for replies.
Correct answer try67

Here's my CTRL  J response:

TypeError: this.getField("Dropdown" + i) is null

3:Field:Calculate


That means one of the fields is not named correctly. Try this code:

var total = 0;

for (var i=1; i<=83; i++) {

    var fname = "Dropdown"+i;

    var f = this.getField(fname);

    if (f==null) {

        console.println("Error: " + fname);

        continue;

    }      

    if (f.valueAsString=="S") {

          total++;

    }

}

event.value = total;

1 reply

try67
Community Expert
Community Expert
March 13, 2017

As the custom calculation script of the "total S" field, enter something like this (I'm assuming the drop-down fields are named "Dropdown1", "Dropdown2", etc.):

var total = 0;

for (var i=1; i<=83; i++) {

    if (this.getField("Dropdown"+i).value=="S") {

          total++;

    }

}

event.value = total;

CourtnessJames
Participant
March 14, 2017

That did not work.  I renamed my fields Dropdown1, to Dropdown23. I copied and pasted the calculation into the properties, custom calculation script.  Is there something else I need to do?

This would be such a major benefit to the project I'm working on.  Thank you. - Anyone and Everyone.

try67
Community Expert
Community Expert
March 14, 2017

Please be more specific... What exactly happened? Are there any error messages in the JS Console?