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.
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.
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.
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?
Copy link to clipboard
Copied
All properties and methods are listed in the Acrobat Javascript Reference.
Copy link to clipboard
Copied
Assuming the field name is correct that should have worked. Are there any error messages in the JS Console?
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.
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"]);
Copy link to clipboard
Copied
Do these fields have a calculated value?
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.