Copy link to clipboard
Copied
I have a date field that I want to be autofilled with the current date when the form is submitted. How is that done?
I would also like to reset the entire form when the form is submitted. How is that done?
Copy link to clipboard
Copied
Hi there
We are sorry for the trouble. As described you want to autofill the date whrn the form is submitted
Please take a look at the similar discussions below and see if that works for you.
Hope it will help
Regards
Amal
Copy link to clipboard
Copied
What trouble are you sorry for?
Copy link to clipboard
Copied
No trouble. I am creating an order form that will be accessed by customers through my company's website and I have created the form but have 4 items that I need help with. I have very little experience with JavaScript (JS) but have figured out how to do a few things. The items I need help with are:
I appreciate your help.
Copy link to clipboard
Copied
My reply was to Amal, not to you. I simply don't like this boilerplate "We're sorry for the trouble" text, as it's meaningless and often not relevant to the situation, like in your case...
Copy link to clipboard
Copied
I am using this script to set the order date when the file is opening but what/how do I revise this script to set the date when the form is Submitted?
this.addScript("init", "var f = this.getField(\"Today\"); if (f.value==\"\") f.value = new Date();");
Copy link to clipboard
Copied
That script does not set the date, it adds a script that sets the date... You only need to run it once.
To set the date when the file is submitted you will need to add the same code to your Submit button.
Copy link to clipboard
Copied
I am trying validate that the delivery date is >= (order date +14 days) and I wrote the following script but nothing seems to be happening:
("Delivery Date")>=("Order Date")+14
I am sure there is but is there a better way to write this?
Copy link to clipboard
Copied
Working with dates is much more complicated than that.
Read these tutorials:
https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript
https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-2
https://acrobatusers.com/tutorials/working-date-and-time-acrobat-javascript-part-3-3
Copy link to clipboard
Copied
Thanks. One thing that I have noticed about us humans is that if we can complicate something we will.
Copy link to clipboard
Copied
I don't think it's an over-complication. What you tried to do is an over-simplification of a complex subject.
Just so you know, other programming languages have a much more complex Date object than JavaScript, including complete separate implementations for the Gregorian calendar, the Julian calendar, the Muslim calendar, the Jewish calendar, the Japanese calendar, etc.
Copy link to clipboard
Copied
Thank you for the articles. They helped me figure out the script below. I inserted the script to set the "Order Date" into the SUBMIT button as you suggested above and it works perfectly. After this date script I added the following script to confirm the injection date is 14 or more days past the "Order Date" but of course it does not work. I chose to add this script to the SUBMIT button (but after the Orer Date script) because the Order Date is not added until submitting but should it be added to the Validation tab for the "Inj Dt Dog 6" field?
The customer adds the injection date and it is formatted the same as the order date (mm/dd/yyyy).
var strStart = this.getField("Order Date").value;
var strEnd = this.getField("Inj Dt Dog 6").value;
if(strStart.length && strEnd.length)
{
var dateStart = util.scand("mm/dd/yyyy",strStart);
var dateEnd = util.scand("mm/dd/yyyy",strEnd);
var diff = dateEnd.getTime() - dateStart.getTime();
var oneDay = 24 * 60 * 60 * 1000;
var days = Math.floor(diff/oneDay) >= 14;
}
else
app.alert("Injection Date for Dog 6 needs to be 14 days past Order Date");
Thanks for your input and help!
Copy link to clipboard
Copied
try67
I added the following script to the SUBMIT button butand removed all the script on the "Order Date" field but the when the file is opened the Order Date field updates to the current date instead of waiting for the SUBMIT button to be selected. Why is that?
this.addScript("init", "var f = this.getField(\"Order Date\"); if (f.value==\"\") f.value = new Date();");
Copy link to clipboard
Copied
Again, this code does NOT set the field's value. It adds a script to the file that does.
To set the field's value directly use this:
var f = this.getField("Order Date"); if (f.value=="") f.value = new Date();
Copy link to clipboard
Copied
Thanks for your help but I must be doing something wrong. I deleted the old script and added the script you suggested to the SUBMIT button so that the current date would not be added to the Order Date field until the SUBMIT button was selected but when I reopened the file the Order Date field immediately updated to the current date.
Copy link to clipboard
Copied
That's because you already added that code as a doc-level script... Go to Tools - JavaScript - Document JavaScripts and delete the "init" script from there.
Copy link to clipboard
Copied
Thank you.
For the other items that I am trying to create (listed below) can you recommend anyone that could help me with the JavScript?
Thanks for your help and have a great weekend!
Copy link to clipboard
Copied
I can set it all up for you, for a small fee. You can contact me directly via [try6767 at gmail.com].