Copy link to clipboard
Copied
Hello, I am trying to find a JavaScript code that allows me to count the numbers of text fields that have contents in them.
I was able to do it for check boxes using the following code:
Var sum = 0;
for (var i = 1; i < 70; i +=) {
if (getField("V" + i).value == "Yes") {sum += 1}
event.value = sum;
}
Hi,
Assuming the naming is something similar that enables you to loop through them then you can check the contents by calling:
if (this.getField("T" + i).value != "") { sumText += 1}
i have assumed the text fields are call T1, T2, T3, etc. respond to this if they are not?
Copy link to clipboard
Copied
Hi,
Assuming the naming is something similar that enables you to loop through them then you can check the contents by calling:
if (this.getField("T" + i).value != "") { sumText += 1}
i have assumed the text fields are call T1, T2, T3, etc. respond to this if they are not?
Copy link to clipboard
Copied
Thank you so much! Your answer helped me solve the issue. Below is the final look of the script that finally worked.
var sum = 0;
var sumText = 0;
for (var i = 1; i < 150; i += 1) {
if (getField("V" + i).value == "Yes") {sum += 1}
if (this.getField("A" + i).value != "") {sumText += 1}
event.value = sum/sumText*100;
}
Copy link to clipboard
Copied
Hi, is there a way for me to manipulate the script and ensure this field remains blank if ("A" + i). value is blank? I keep getting this error message when all the fields are empty. Thanks.
Copy link to clipboard
Copied
You can use this script:
var total = 0;
for (var i = 0; i < this.numFields; i++) {
var oFld = this.getField(this.getNthFieldName(i));
if ((oFld.type == "text") && (oFld.value != "")) {
total = total +1;
}}
console.clear();
console.show();
console.println("Total: " +total);