PDF-Forms is a service provided by PDFzone.com | http://www.pdfzone.com/ __________________________________________________________________
This is great. I am learning a great deal from this list. The code samples really help. Otherwise, I would certainly be stuck. -----Original Message----- From: Day, Tim G. [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 30, 2004 9:53 AM To: [EMAIL PROTECTED] Subject: RE: [PDF-Forms] Need Custom Calculation Script to format date Carol, It sounded to me like you wanted maximum flexibility for date entries (admirable but difficult to achieve, I believe), but if the below solution is satisfactory, here's a function I wrote to validate dates. It displays an error message if the date is not entered in "MM/DD/YYYY" format; it includes extra, optional logic to compare the date to the system date and displays a warning message when appropriate. Also, it uses another function named "Trim", which I have also included after the code for function "ValidDate". Here's an example call to the function if the date should be "Before" the system date: ValidDate("Before", "Date of Birth"); function ValidDate(BeforeAfter, DateName) { // This function validates dates entered in MMDDYYYY format and compares them to the system date if the first argument is included. // Arguments: BeforeAfter specifies whether the current date should be either "Before" or "After" the system date; DateName is the name of the current date field (for use in comparison to the system date)--if omitted, the date name defaults to "Date". // Note: The arguments should be omitted if the date should not be compared to the system date. var nWarning = 1; event.value = Trim (event.value, true, true); if (event.value != "") { event.value = util.printx("99/99/9999", event.value); var result = AFParseDateEx(event.value, "mm/dd/yyyy"); if (result == null) {app.alert("Invalid Date: Re-enter in MMDDYYYY or MM/DD/YYYY format."); event.rc = false; return false;} // Else date is valid else { // Compare entered date to system date. var SysDate = new Date; SysDate = AFParseDateEx(SysDate, "mm/dd/yyyy"); // If the current date should be after the system date if (BeforeAfter == "After") { // If the current date is before the system date if (result.valueOf() < SysDate.valueOf()) { // If the name of the current date is not provided if (DateName == undefined) DateName = "Date"; app.alert("Warning: " + DateName + " is before the system date.", nWarning); } } // Else if the current date should not be after the system date // Note: An "else-if" rather than just an "else" is used in case the BeforeAfter argument is not provided (in which case no comparison is made to the system date). else // If the current date should be before the system date if (BeforeAfter == "Before") // If the current date is after the system date if (result.valueOf() > SysDate.valueOf()) { // If the name of the current date is not provided if (DateName == undefined) DateName = "Date"; app.alert("Warning: " + DateName + " is after the system date.", nWarning); } return true; } } // Else date is blank or null else return false; } // Trim leading and trailing spaces; set L = true to trim leading spaces and set T = true to trim trailing spaces. function Trim(s, L, T) { // Remove any leading spaces if (L) s = s.replace(/^[ ]+/, ""); // Remove any trailing spaces if (T) s = s.replace(/[ ]+$/, ""); return s; } -----Original Message----- From: [EMAIL PROTECTED] on behalf of McDowell, Carol Sent: Tue 3/30/2004 9:01 AM To: '[EMAIL PROTECTED]' Cc: Subject: RE: [PDF-Forms] Need Custom Calculation Script to format date PDF-Forms is a service provided by PDFzone.com | http://www.pdfzone.com/ __________________________________________________________________ This works for me! Thanks so much for your help. -----Original Message----- From: J Bealer [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 30, 2004 8:27 AM To: [EMAIL PROTECTED] Subject: RE: [PDF-Forms] Need Custom Calculation Script to format date PDF-Forms is a service provided by PDFzone.com | http://www.pdfzone.com/ __________________________________________________________________ Carol, Using Acrobat's own date validation, you could try something like this, substituting your own alerts, in the Custom Validate script of your date field : if(event.value) { var DateOK = AFParseDateEx(event.value,"mm/dd/yyyy"); if(DateOK != null) { app.alert("date ok"); event.value = util.printd("mm/dd/yyyy", DateOK); } else { event.value = ""; app.alert("date not ok"); } } >From: "McDowell, Carol" <[EMAIL PROTECTED]> >Reply-To: [EMAIL PROTECTED] >To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]> >Subject: [PDF-Forms] Need Custom Calculation Script to format date >Date: Mon, 29 Mar 2004 11:16:42 -0500 > > >PDF-Forms is a service provided by PDFzone.com | >http://www.pdfzone.com/ >__________________________________________________________________ > >I'm a beginner with using javascript in forms. I'd appreciate help >with >the >following problem: > >I have a date field where the user will type in a date value. I want >to >use >a custom calculation script where no matter what the user types in for the >date, it will reformat it to mm/dd/yyyy. For example, if the user types >"03/29/04" or "March 29, 2004", I want the value to change to "03/29/2004" >automatically. > >I don't want to use the format field category because when the user >doesn't type the date with this format, an invalid date/time warning >pops up that says to make sure the date/time exists and that the format should match the >format mm/dd/yyyy. I'd rather write my own warning in the custom >calculation script if the user types in anything other than a date. > >Thanks. > >To change your subscription: >http://www.pdfzone.com/discussions/lists-pdfforms.html > _________________________________________________________________ Get rid of annoying pop-up ads with the new MSN Toolbar - FREE! http://toolbar.msn.com/go/onm00200414ave/direct/01/ To change your subscription: http://www.pdfzone.com/discussions/lists-pdfforms.html To change your subscription: http://www.pdfzone.com/discussions/lists-pdfforms.html To change your subscription: http://www.pdfzone.com/discussions/lists-pdfforms.html
