Copy link to clipboard
Copied
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
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++
Copy link to clipboard
Copied
Before the if statement add this:
console.println(aFields + ": '" + this.getField(aFields).valueAsString + "'");
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
What can you see in the console?
Copy link to clipboard
Copied
ReferenceError: aFields is not defined
1:Console:Exec
undefined
Copy link to clipboard
Copied
when I put the below script in the console
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;
for (i = 0; i < aFields.length; i++) { console.println(aFields + ": '" + this.getField(aFields).valueAsString + "'");
if (this.getField(aFields).valueAsString != "") count++
}
event.value = count;
IT GIVES "25"
but the the Radio field and Dropdown field is counted as filled even before selecting
Copy link to clipboard
Copied
Console gives something like this:
1: ''
2: ''
3: ''
4: ''
5: ''
6: ''
7: ''
8: ''
9: ''
10: ''
11: ''
12: ''
13: ''
14: ''
15: ''
16: ''
17: ''
18: ''
19: ''
20: ''
21: '-Select-'
22: ''
23: ''
24: ''
25: 'Off'
Copy link to clipboard
Copied
Looks like that the dropdown gives the value "-Select-" and the unselected radio box the value "Off".
For the field names use this:
var aFields = new Array("Text1", "Text2", "Text3", "Text4", "Dropdown1", "Dropdown2");
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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++
Copy link to clipboard
Copied
Try67 sir,
Thank for the suggestion, it has made code simple and saved lot of time.
Thanks once again.