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

How can you combine multiple date fields into a single text field?

vwilliams
Registered: Feb 6 2008
Posts: 35
Answered

Greetings,
I am working w/ Adobe 6 & 7 and I am a novice programmer in Adobe although I have programmed in other languages.
I am trying to write a quick javascript that will take the data from three date fields; d-2 digit text field, m-2 digit drop down, y-4 digit text field and combine them into one text field. I was trying to keep it simple since we are using multiple versions of Adobe.
I added this code first to the Year field and then to a button but neither is working. I added a few alerts and found even though the three fields are not == 0 1st part of the code is partially executing, i.e. app.alert("MVRHEADER.VSTDTD") pops up but the field is not set to NONE. In truth the ELSE should execute instead anyway. I seem to have multipe problems.
Can anyone help and/or direct me to an example?

Thank you,
Valerie

var xVSTDTD = this.getField("MVRHEADER.VSTDTD");
var xVSTDTM = this.getField("MVRHEADER.VSTDTM");
var xVSTDTY = this.getField("MVRHEADER.VSTDTY");
var xVSTDT = this.getField("MVRHEADER.VSTDT");

if ((xVSTDTD.value.length == 0) || (xVSTDTM.value.length == 0) || (xVSTDTY.value.length == 0))
{
app.alert("MVRHEADER.VSTDTD");
xVSTDT = "NONE";
}

else
{
app.alert("In the else");
xVSTDT = xVSTDTD;
}

My Product Information:
Acrobat Standard 6.0.6, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You can try something like the following as the text field's custom calculation script:

// Get field references
var xVSTDTD = getField("MVRHEADER.VSTDTD");
var xVSTDTM = getField("MVRHEADER.VSTDTM");
var xVSTDTY = getField("MVRHEADER.VSTDTY");

if ((xVSTDTD.value == "") || (xVSTDTM.value == "") || (xVSTDTY.value == "")) {
app.alert("MVRHEADER.VSTDTD");

// Set this field value
event.value = "NONE";

} else {
app.alert("In the else");

// Set this field value by concatenating d, m, y, with a "/" separator
event.value = xVSTDTD.value + "/" + xVSTDTM.value + "/" + xVSTDTY.value

}

This may not be exactly what you need, but it should get you started.

George
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
If you want to check the validity of the date you will need to use some additional code to validate the date, for example:

// Get field references
var sDate = getField("MVRHEADER.VSTDTD").value;
var sMonth = getField("MVRHEADER.VSTDTM").value;
var sYear = getField("MVRHEADER.VSTDTY").value;
event.value = ''; // clear field
// test for empty values in selection assuming no selction is a single space
if ( (sDate != ' ') & (sMonth != ' ') & (sYear != ' ') ) {
// test for vald date selection
var sTest = util.scand("dd/mm/yyyy", sDate + "/" + sMonth + "/" + sYear);
if( sTest == null)
app.alert("Invalid date date selection"); // invalid date
else
event.value = util.printd("dd/mm/yyyy", sTest); // Set this field value by concatenating d, m, y, with a "/" separator and formatting
}

George Kaiser

vwilliams
Registered: Feb 6 2008
Posts: 35
The first post worked w/ a little modification. Instead of using event.value I used fieldname.value.

What I'm noticing though is the month value is null even though it was completed. That data is w/in a drop down field. Do I need to use something beyond/other than .value?

I'll check the 2nd post as well.

// Get field references
var xVSTDTD = getField("MVRHEADER.VSTDTD");
var xVSTDTM = getField("MVRHEADER.VSTDTM");
var xVSTDTY = getField("MVRHEADER.VSTDTY");
var xVSTDT = getField("MVRHEADER.VSTDT");

//if ((xVSTDTD.value == "") || (xVSTDTM.value == "") || (xVSTDTY.value == ""))
if (xVSTDTM.value == "")
{
app.alert("MVRHEADER.VSTDTD");

// Set this field value
xVSTDT.value = "NONE";

} else {
app.alert("In the else");

// Set this field value by concatenating d, m, y, with a "/" separator
xVSTDT.value = xVSTDTD.value + "/" + xVSTDTM.value + "/" + xVSTDTY.value

}
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Where exactly have you placed this code? What field and what event?

George
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
My code was written using Acorbat Forms JavaScript and it should be placed in the "Custom calculation script" for the field containing the combined text, "event.value".

George Kaiser

vwilliams
Registered: Feb 6 2008
Posts: 35
I put this code in a button, mouse up, run js. The var xVSTDT is the field I'm trying to set and I used xVSTDT.value = "NONE"; instead of event.value = "NONE"; which worked.

After walking away I found my error (typo - ugh!!!!) and the month is now being retreived and set.

I'll accept your answer and I appreciate your help!
Thanks again!!!!
vwilliams
Registered: Feb 6 2008
Posts: 35
Apparently "gkaiseril" and I were answering at the same time.

I added the same exact code as my 2nd entry to the year field under "Custom calculation script" and that worked successfully too. I'm going to use this so the end user doesn't have to click on a button to derive the date.

When I changed code to "event.value" on the year field, the year field was set to "NONE" instead of leaving the "2008" already entered and the xVSTDT field was not set at all. When I add the code to the xVSTDT field it's not working at all regardless of what *.value I use.

I hope this helps. Cheers!
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
The code I posted is intended to be the custom calculation script of the field that will display the date. You should not have a calculation script for any of the input fields. Calculated fields should also be set to read-only.

George
vwilliams
Registered: Feb 6 2008
Posts: 35
George,
I understand what your code is supposed to do fully now. Unfortunately I need the date w/in 4 fields, i.e. d, m, y, complete. With your help I was able to update the code to what I needed.

Thank you,
Valerie