Copy link to clipboard
Copied
I have created a form which will be filled in over several days. When a checkbox is ticked, I want the date field next to it to automatically fill in with today's date. I don't want this entry to update when the date changes; it needs to record when that particular box was ticked.
Please could you help me write a script to help this occur? I have to then cover about 40 pages with the same fields, so would like to get it right before I go on a copying session! Thanks very much.
- You had the Date format still selected under the text field.
- You had an invalid script under the text field's Validation event.
- You had the wrong date format in the code of the check-box.
- The code of the check-box was only set to update the field when it was empty, so clicking it did nothing once that was the case.
- The code of the check-box did not clear the text field when you un-checked it.
Copy link to clipboard
Copied
Enter the following mouse up action script in the check box (assuming the text field name is Date):
if(!this.getField("Date").value && event.target.value!="Off")
{this.getField("Date").value = util.printd("mm/dd/yyyy", new Date());}
The blue text ensures the date will not update after it has already been entered. If you want it to update every time the box is checked, remove the blue text from the script.
Copy link to clipboard
Copied
How can it update all the time if it's triggered by Mouse UP action?
You are missing 'd' in util.printd.
Copy link to clipboard
Copied
By "all the time" I meant if the box is checked again.
Copy link to clipboard
Copied
Thanks so much! It looks like that has worked. Is there a quick way of duplicating both the check box and date field 6 times on 40-odd pages? Will it update the field names automatically in the Javascript? I know how to do multiple copies, etc.
Copy link to clipboard
Copied
Also - the date only appears when I click in the date field, and then disappears again. Anyway to get it to appear automatically and stay there please?
Copy link to clipboard
Copied
It should stay. If it only appears when you click in it that probably means the date field is formatted differently than the format the check box is sending to it. You can either remove the formatting in the date field, match the formatting to the script (mm/dd/yyyy), or adust the format in the scrip to match the Date field. An easy way to duplicate this would be to create the original checkbox next to the date field and name the check box "Date Trigger" (for this example). Then change the script to the following:
var num=event.target.name.replace("Date Trigger.","");
if(!this.getField("Date."+num).value && event.target.value!="Off")
{this.getField("Date."+num).value = util.printd("mm/dd/yyyy", new Date());}
Next, in form editing mode, select both fields, right-click one of the fields and select Create muliple copies. Select 1 for across. For down, enter the number of field pairs you want. Move the fields throughout the document by cutting, pasting, and repositioning them. Here's a full explanation of how this works:
https://pdfautomationstation.substack.com/p/anticipating-field-names-in-custom
Copy link to clipboard
Copied
Thanks once again for your help. I've amended the date format in the Javascript as suggested but the date still doesn't stay visible - and also the format hasn't changed. I'm trying to get it to show day-month-year but despite me changing it to this in both the Javascript and the date field properties it still shows month-day-year.
Copy link to clipboard
Copied
It will show it according to what you specify in the code. In the example above it's "mm/dd/yyyy" which means "month/day/year". Change that part of the code if you want a different format.
Copy link to clipboard
Copied
I've changed them both to be the same but the date still doesn't show - and it hasn't changed either. This is the date field:
Copy link to clipboard
Copied
And this is the Javascript
Copy link to clipboard
Copied
Screenshot of the completed date field:
Date disappears when you exit the field
Copy link to clipboard
Copied
There must be something else at play there. Can you share the file?
Copy link to clipboard
Copied
PS. You should change the field's Format to None, and let the script take care of the value.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I've now got it to show the date, but only if I use American format (month, day, year). The date doesn't disappear if the box is unchecked, which we will need to ensure happens as otherwise it'll look like you've done a task you haven't actually done.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
AMAZING! Thank you so much! What was I doing wrong?
Copy link to clipboard
Copied
- You had the Date format still selected under the text field.
- You had an invalid script under the text field's Validation event.
- You had the wrong date format in the code of the check-box.
- The code of the check-box was only set to update the field when it was empty, so clicking it did nothing once that was the case.
- The code of the check-box did not clear the text field when you un-checked it.
Copy link to clipboard
Copied
So - er - quite a lot then. 😄 I really appreciate your help; I've never done anything like this before and was doing my best to Google but getting confused. Thanks so much. I wil now try the duplication and see what happens!
Copy link to clipboard
Copied
Stupid question alert - I've now used the script you gave me to create multiple copies, but the date isn't appearing again. have I put the script in the wrong place? I put it in the Checkbox field which is where I thought you meant it should go.
Copy link to clipboard
Copied
Did you adjust the code to have the relevant text field's name, instead of the original one?
Copy link to clipboard
Copied
Yes - I renamed it as Date Trigger, as you said.
I replaced the original script with the one you put in, and that didn't work. Then I tried putting one script in after another, and that didn't work either.
Copy link to clipboard
Copied
Stupid question but you said to put the date trigger checkbox right next to the date field - does that mean I have to change where the checkbox is at the moment? As that is going to cause me some troubles. If I try to create a copy of the original checkbox & date field then none of them work.
Copy link to clipboard
Copied
The location doesn't matter. I said to put it next to it so it's easy to create multiple copies of both simultaneously.