Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

What is Javascript for clear field?

Community Beginner ,
Apr 03, 2023 Apr 03, 2023

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? 

TOPICS
Acrobat SDK and JavaScript
921
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 03, 2023 Apr 03, 2023

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 03, 2023 Apr 03, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 12, 2023 Apr 12, 2023

Thank you Test Screen Name, 

 

So would the script look like this for case 1? 

 

CASE 1:-

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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 12, 2023 Apr 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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 14, 2023 Apr 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 14, 2023 Apr 14, 2023
LATEST

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
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines