Skip to main content
Participating Frequently
April 3, 2023
Question

What is Javascript for clear field?

  • April 3, 2023
  • 3 replies
  • 1008 views

I am trying to figure out how to clear fields via javascript if a checkbox is triggered. Anyone have a script? What exactly is the JS term to clear fields? 

This topic has been closed for replies.

3 replies

JR Boulay
Community Expert
Community Expert
April 14, 2023

"So would the script look like this for case 1? "

 

for (var i = 1; i < 4; i++) {
this.getField("Field" + i).value = "";
}

Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
Community Expert
April 14, 2023

That's in case those are the actual field names. A more generic example is this:

 

var fields = ["Field1", "Field2", "Field3"]; // replace with actual field names
for (var i in fields) {
	this.getField(fields[i]).value = "";
}
Legend
April 3, 2023

It depends whether you mean "set to blank" or "set to default value (which might not be blank)".

Case 1: set to empty string (or what is appropriate for non-text fields)

Case 2: resetForm indeed.

Participating Frequently
April 12, 2023

Thank you Test Screen Name, 

 

So would the script look like this for case 1? 

 

CASE 1:-

this.emptyString(["Field1", "Field2", "Field3"]);

 

Legend
April 12, 2023

No, that's not how you would clear the fields to an empty string instead of the default (case 1). There is no single call for that, you need to reset each one separately or in a loop. 

try67
Community Expert
Community Expert
April 3, 2023

this.resetForm(["Field1", "Field2", "Field3"]);