Skip to main content
Participating Frequently
Apr 3, 2023 1:36 PM UTC
Question

What is Javascript for clear field?

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 is closed to new replies. Start a new post to keep the conversation going.

6 replies

JR Boulay
Community Expert
Community Expert
Apr 14, 2023 9:54 AM UTC

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

 

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

Translate
Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
Community Expert
Apr 14, 2023 11:02 PM UTC

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 = "";
}
Translate
Legend
Apr 3, 2023 7:38 PM UTC

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.

Translate
Participating Frequently
Apr 12, 2023 12:57 PM UTC

Thank you Test Screen Name, 

 

So would the script look like this for case 1? 

 

CASE 1:-

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

 

Translate
Legend
Apr 12, 2023 1:05 PM UTC

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. 

Translate
try67
Community Expert
Community Expert
Apr 3, 2023 1:38 PM UTC

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

Translate