These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Date and time

RR
Registered: Feb 15 2010
Posts: 7
Answered

Looks like I'm digging a hole for myself. (Valantine is over.) I need to create a form!

The "user" wants to type the date and the time without spaces: 15022010 resulting in 15-02-2010.
Acrobat converts 15/02/2010 and 15:02:2010 by it self to the requested 15-02-2010 just by selecting the formating notation. So this without the spaces is an extra wish!

I don't want to loose the features where: / feb ; is converted dd-mm-yyyy

In the form there is asked for a lot of other numbers.

Here is the script I use now:

date_val("1.5");
 
///----------------------
function current_date( f )
{
var x = getField ( f );
var cDate = util.printd("dd-mm-yyyy", new Date());
if (x.value == "") {
   x.value = cDate;
   }
}
 
///-----------------------
function date_val ( f ) {
var x = getField( f );
var d1 = util.scand("dd/mm/yyyy", x.value);
var d2 = new Date();
var givenyear = d1.getFullYear();
var thisyear = d2.getFullYear();
var diff = givenyear - thisyear;
 
if (diff > 10) { 
    app.alert("\nCheck the date.",2,0);
    getField(f).setFocus();
    return false;
}
 
// ------------------------- 
else if (( (d2.valueOf() - d1.valueOf()) / 1000 ) < -86399 ){
    app.alert ("\nThe date of travel in the future is invalid.",2,0)
    getField(f).setFocus();
    return false;
 
}
 
// -------------------------
if (( (d2.valueOf() - d1.valueOf()) / 1000 ) >= 7776000 ){
    app.alert ("\nThe date of your request has expired.",2,0)
    getField(f).setFocus();
    return false;
}
return true;
}

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
So how exactly are these functions related to the date parsing functinality you've asked about? And where is this code being run?

If you want some special formatting for the field you'll need to write you're own custom format script.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

RR
Registered: Feb 15 2010
Posts: 7
Hi Thom,

It is not intended to be document code. The code above refers only to one field.
May be I am wrong but I was thinking that a solution for the date without spaces might influence on other numbers like: phone number, bank account number, etc. So the date code for date input without spaces has to be specific for this field.

Until now I haven't made general scripts that influence the whole file. That is why.

Cheers,

RR
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I'm still not sure what you are getting at. You started off by stating that you want the user to be able to enter a date without any formatting, and then have that set of entered numbers be automatically formatted as a date. Then you present some code that has nothing to do with this activity.

It's Possible we're having a problem with terminology. But I believe that what you need is either a custom Keystroke or custom Format script. Please read these articles

http://www.acrobatusers.com/tutorials/2006/scripts_form_fields
http://www.acrobatusers.com/tutorials/2006/formatting_text_fields


Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

RR
Registered: Feb 15 2010
Posts: 7
Hi Thom,

I mixed up global and local scripting. You are right it has nothing to do with my question. Mae culpa, sorry for that, I am a foreigner and new to Java and "programming" and …

Thank you for pointing to the The Acrobat JavaScript Reference.
Also bought a book: The definitive guide of Davis Flanagan. There is a lot of gold to dig in the Ref and that book.

The format Event is probably the solution for the date entry without spaces and generating output dd-mm-yyyy.
It is interesting to find that out before tomorrow!

Was curious and wanted to have a look at the example file, Formatting Text Fields. The link to the example is broken.

Thank you.

Bye for now.

RR
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I reported the broken link and placed a copy of the format example here:
http://www.windjack.com/DownLoads/FormattingExamples.pdf

Good to here your coming up to speed on Acrobat JavaScript. You might be interested in the videos at www.pdfscripting.com

A simple format script might solve your issue. A simple way to do this would be to extract just the numbers from the input value by using a regular expression. The reformatting with the "util.printx()" function. Look it up in the Acrobat JavaScript Reference.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script