Skip to main content
David Healy
Inspiring
June 24, 2021
Question

I need help with Javascript in Acrobat

  • June 24, 2021
  • 1 reply
  • 12675 views

In Acrobat I need:

  • a field “Date-2” that subtracts 2 days from a field named,“DateMAIN

Field “DateMAIN” will display the date as, “June 5, 2021”  (mmm d, yyyy)

Field “Date-2” will display the date as, “6/3/21”  (mm/dd/yy)

  • a field  “Time-330” that subtracts 3 hours and 30 minutes from a field named,“TimeMAIN

Field “TimeMAIN” will display the date as, “June 5, 2021”  (mmm d, yyyy)

Once I obtain the code do I enter it in the Custom Calculation Script window?

This topic has been closed for replies.

1 reply

bebarth
Braniac
June 24, 2021

For the Day-2 field, in validation script of the DateMAIN field place this script:

this.getField("Day-2").value=util.printd("mm/dd/yy", new Date(util.scand("mmm d, yyyy",event.value)-(1000*3600*24*2)));

The format of the DateMAIN field is "mmm d, yyyy".
I don't understand the format of both time fields are not they in a time format?
@+

David Healy
Inspiring
June 24, 2021

Which window should I enter this code into: JavaScript Debugger, Actions, Custom Calculation Script or other?

 

Attached is how it should look:

David Healy
Inspiring
June 28, 2021

The undefined value comes because you didn't set the TimeMain fiels with the right date format else you would have this message!

I modified a bit both scripts. Now the calculated date and time fields will be blank if the main fields are blank.
Here are both new scripts:
For the dates I wrote it in 2 different ways only to show you the possibilities.

 

this.getField("D-2").value=event.value!=""?util.printd("m/d/yy", new Date(util.scand("m/d/yy",event.value)-(1000*3600*24*2))):"";
this.getField("D-3").value=event.value==""?"":util.printd("m/d/yy", new Date(util.scand("m/d/yy",event.value)-(1000*3600*24*3)));

 

And for the times.

 

var theTime=event.value.toString().split(" ");
var theHour=theTime[0];
var ampm=theTime[1];
var theHour=theHour.split(":");
var theHours=Number(theHour[0]);
var theMinutes=Number(theHour[1]);
var inMinutes=(theHours*60)+theMinutes;
function timeCalculation(interval,theField) {
	if (theTime!="") {
		newMinutes=inMinutes-interval;
		var pmam=ampm;
		if (theHours==12) {
			if (pmam=="am") var pmam="pm";
			else var pmam="am";
		}
		var newHours=Math.floor(newMinutes/60);
		newMinutes-=newHours*60;
		if (newMinutes<10) var newMinutes="0"+newMinutes;
		if (newHours<=0) {
			newHours+=12;
			if (ampm=="am" && newHours!=12) var pmam="pm";
			else if (newHours!=12) var pmam="am";
		}
		this.getField(theField).value=newHours+":"+newMinutes+" "+pmam;	
	} else this.getField(theField).value="";
}
timeCalculation(255,"T-415");
timeCalculation(270,"T-430");

 

I hope that suits you.
@+


That works! For some reason a pop-up menu appears with a calendar which is better

What is involved with making the time selection appearing the same way? I thought this would make it easier in regards to specifying time as on a 12-hour vs. 24-hour clock. Here is an illustration: