Second Date should come After First Date - Only works sometimes
Hi,
Using Adobe Acrobat XI Pro - Forms
Can someone please help me with my code for these date fields? I had some pretty simple code to compare two dates, but apparently it is too simple.
Sometimes it works, and sometimes it doesn't work.
I am trying to say: If the "From Date" is newer than the "To Date," then give an alert, and have the person correct the "To Date." (Because the "To Date" should come after the "From Date.")
I am trying to do this for two different types of date formats. I have the date formats set in the field properties of the date fields.
One set of date fields is using mm/yyyy, and the other set of date fields is using mm/dd/yyyy.
The code is located in the Second Date Field properties, on the Action Tab, using "On Blur/Run a Javascript."
Here is my code:
| var fd = this.getField("FromDate1").value; | |
| var sd = this.getField("ToDate1").value; | |
| if (fd != "" && fd > sd) { | |
| app.alert ("From Date must come before To Date."); |
//Below resets the value of the 2nd Date, but moves on to next field
| this.getField("ToDate1").value = ""; |
//Below sets the focus back to the 2nd Date, so you can try again
| this.getField("ToDate1").setFocus(); |
}
Here is a link to my form on Dropbox:
Thank you very much.
