Skip to main content
rakeshk21205956
Inspiring
May 4, 2019
Answered

Counting Fields: Dropdown & Radio button field is always counted as filled

  • May 4, 2019
  • 1 reply
  • 852 views

I want to display number of fields filled.... everything is working correct but the dropdown field is being counted as filled already even before it is been selected with a value;

var totalfields = new Array(Text1, Text2, Text3, Text4, Dropdown1, Dropdown2);

var count = 0;

for (i = 0; i < totalfields.length; i++) {

if (this.getField(aFields).valueAsString != "") count++

}

event.value = count;

The above script displays  2 always  i.e. it presumes Dropdown are filled beforehand .

Same is the case with Radio buttons... it is also showing as filled before selecting any option.

Any solution so that it should show 0.

Thanks

This topic has been closed for replies.
Correct answer try67

Thanks for your help it is working now.

Below is the script. plz suggest any better way (if any):

var aFields = new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25);

var count = 0; // variable to store count of non-empty fields

for (i = 0; i < aFields.length; i++) {     

if (this.getField(aFields).valueAsString != "" && this.getField(aFields).valueAsString != "-Select-" && this.getField(aFields).valueAsString != "Off" ) count++

} // end loop

event.value = count;


It's not good practice to hard-code values into your code.

Replace this line:

if (this.getField(aFields).valueAsString != "" && this.getField(aFields).valueAsString != "-Select-" && this.getField(aFields).valueAsString != "Off" ) count++

With this:

var f = this.getField(aFields);

if (f.valueAsString != f.defaultValue) count++

1 reply

Bernd Alheit
Community Expert
Community Expert
May 4, 2019

Before the if statement add this:

console.println(aFields + ": '" + this.getField(aFields).valueAsString + "'");

rakeshk21205956
Inspiring
May 4, 2019

var aFields = new Array(Text1, Text2, Text3, Text4, Dropdown1, Dropdown2);

var count = 0; // variable to store count of non-empty fields

for (i = 0; i < aFields.length; i++)

{console.println(aFields + ": '" + this.getField(aFields).valueAsString + "'");

if (this.getField(aFields).valueAsString != "") count++

} // end loop

event.value = count;

Still Not working?? it still show 2 dropdown field filled

Bernd Alheit
Community Expert
Community Expert
May 4, 2019

What can you see in the console?