Highlighted

Resetting a date field

Community Beginner ,
May 24, 2019

Copy link to clipboard

Copied

How do I reset a date field to blank with javascript?  I've tried field01.value = ""; but that doesn't work.

I have a checkbox, and if that box is checked, I want 2 date fields to be required.  I've tried field01.required = true; but that doesn't work.

If the user unchecks the box, I want the 2 date fields to be blanked out.

Ok, I finally figured it out.  When I added the date field, in the General tab I used a "Name:" of "DateRangeFrom" and "DateRangeTo".  I formatted them, in the Format tab, with mm/dd/yyyy.  This resulted in them getting actual field names of "DateRangeFrom_af_date" and "DateRangeTo_af_date".  Not the names I had assigned.  This was very confusing and hard to nail down had it not been for discovering the JS Console while working in Adobe Acrobat Pro to console.println a bunch of stuff.

The following code then works:

var fld07 = this.getField("DateRangeFrom_af_date");

var fld08 = this.getField("DateRangeTo_af_date");

fld07.value = "";

fld08.value = "";

Many thanks for the help.

Topics

PDF forms, Windows

Views

445

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Resetting a date field

Community Beginner ,
May 24, 2019

Copy link to clipboard

Copied

How do I reset a date field to blank with javascript?  I've tried field01.value = ""; but that doesn't work.

I have a checkbox, and if that box is checked, I want 2 date fields to be required.  I've tried field01.required = true; but that doesn't work.

If the user unchecks the box, I want the 2 date fields to be blanked out.

Ok, I finally figured it out.  When I added the date field, in the General tab I used a "Name:" of "DateRangeFrom" and "DateRangeTo".  I formatted them, in the Format tab, with mm/dd/yyyy.  This resulted in them getting actual field names of "DateRangeFrom_af_date" and "DateRangeTo_af_date".  Not the names I had assigned.  This was very confusing and hard to nail down had it not been for discovering the JS Console while working in Adobe Acrobat Pro to console.println a bunch of stuff.

The following code then works:

var fld07 = this.getField("DateRangeFrom_af_date");

var fld08 = this.getField("DateRangeTo_af_date");

fld07.value = "";

fld08.value = "";

Many thanks for the help.

Topics

PDF forms, Windows

Views

446

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
May 24, 2019

Copy link to clipboard

Copied

You don't access a field like that. You need to use the proper methods for it, like so:

this.getField("field01")

Then you would be able to access the field's properties and methods.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
May 25, 2019

Copy link to clipboard

Copied

Thanks try67; I've tried

this.getField("field01").value = "";

But that doesn't reset it.  What are the properties and methods of a date field?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
May 25, 2019

Copy link to clipboard

Copied

All properties and methods are listed in the Acrobat Javascript Reference.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Most Valuable Participant ,
May 25, 2019

Copy link to clipboard

Copied

Assuming the field name is correct that should have worked. Are there any error messages in the JS Console?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Advocate ,
May 25, 2019

Copy link to clipboard

Copied

Another approach would be

this.resetForm(["field01"]) ;

or, if that appears too complicated, use

this.getField("field01").value = this.getField("field01").defaultValue ;

However, if this field is the result of a calculation, you'd have to check there too, that it proper resets.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
May 29, 2019

Copy link to clipboard

Copied

I have tried both of the approaches below, and still the date field does not get blanked out.

var fld07 = this.getField("DateRangeFrom");

var fld08 = this.getField("DateRangeTo");

//fld07.value = fld07.defaultValue;

//fld08.value = fld08.defaultValue;

this.resetForm(["DateRangeFrom"]);

this.resetForm(["DateRangeTo"]);

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Most Valuable Participant ,
May 29, 2019

Copy link to clipboard

Copied

Do these fields have a calculated value?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
May 29, 2019

Copy link to clipboard

Copied

Ok, I finally figured it out.  When I added the date field, in the General tab I used a "Name:" of "DateRangeFrom" and "DateRangeTo".  I formatted them, in the Format tab, with mm/dd/yyyy.  This resulted in them getting actual field names of "DateRangeFrom_af_date" and "DateRangeTo_af_date".  Not the names I had assigned.  This was very confusing and hard to nail down had it not been for discovering the JS Console while working in Adobe Acrobat Pro to console.println a bunch of stuff.

The following code then works:

var fld07 = this.getField("DateRangeFrom_af_date");

var fld08 = this.getField("DateRangeTo_af_date");

fld07.value = "";

fld08.value = "";

Many thanks for the help.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Resources
One Stop Solution for Acrobat
Edit a PDF
Add a group