Skip to main content
Participant
April 30, 2024
Question

Como contar campos de texto ocupados en formulario.

  • April 30, 2024
  • 1 reply
  • 539 views

Necesito una sentencia en Java Script para contar campos ocupados con texto (Idem CONTARA en Excel). Tabíen podría ser que cuente casillas de verificación con tilde. Gracias de antemano.

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
April 30, 2024

Do you mean check-boxes that have been ticked?

Participant
April 30, 2024

Thanks for responding. Yes, I want to count only the marked ones.

try67
Community Expert
Community Expert
April 30, 2024

You can do it using this code:

 

var count = 0;
for (var i=0; i<this.numFields; i++) {
	var fname = this.getNthFieldName(i);
	var f = this.getField(fname);
	if (f==null) continue;
	if (f.type=="text" && f.valueAsString!="") count++;
	if ((f.type=="checkbox" || f.type=="radiobutton") && f.valueAsString!="Off") count++;
}
app.alert("Number of filled-in fields: " + count,3);