Skip to main content
Participating Frequently
June 28, 2020
Answered

set limit to date field

  • June 28, 2020
  • 2 replies
  • 1517 views

I have a form with two date fields, "certDate" and "expireDate" (both set to mm/dd/yyyy format). Once a date is entered into the first field, "certDate", the date entered into the second field, "expireDate", can't be more than two years later than the first date. It can be less than two years later than the first date, but can't be earlier than the first date. How should "expireDate" be scripted?

This topic has been closed for replies.
Correct answer Bernd Alheit

Absolutely nothing happens. The validation code might as well not exist. The user can enter anything into the second field. Your suggested code change has no effect whatsoever.


In the second script remove .value from:

if (days.value > 730) {

2 replies

JR Boulay
Community Expert
Community Expert
July 2, 2020
Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
Community Expert
June 29, 2020

You can write a custom validation script to do it. You need to convert the string values of the fields to Date objects and then you'll be able to manipulate those objects and check they don't pass a certain threshold. If they do, you can reject the user's value by setting event.rc as false in your code.

 

See:

https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript
https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-2
https://acrobatusers.com/tutorials/working-date-and-time-acrobat-javascript-part-3-3

Participating Frequently
July 1, 2020

Those tutorials are 14 years old and don't seem to be very helpful. Any other suggestions?

try67
Community Expert
Community Expert
July 1, 2020

They are still relevant, though. Do you have specific issues with them?