Skip to main content
Known Participant
November 28, 2024
Question

Automatically fill date field when a check-box is ticked

  • November 28, 2024
  • 1 reply
  • 6522 views

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.

This topic has been closed for replies.

1 reply

PDF Automation Station
Community Expert
November 29, 2024

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.

Known Participant
November 29, 2024

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.

PDF Automation Station
Community Expert
November 30, 2024

I'm so sorry, I missed the video you had uploaded. That works perfectly now, and I have managed to change the date format. Thank you very much indeed for taking the time to do that. I thought that I had to have both scripts in which is what was getting me confused.

 

Using the article you linked to, I've also been able to create 3 'sum' boxes at the bottom of each page.

 

To create multiple copies of these I would just copy and paste them onto different pages, as you say - and 'create multiple copies' means the formula would move onto the different pages I hope?

 

I'm really grateful for your help - never done anything like this before and in a new role so really want to do a good job.

 

At the bottom of the document, I have boxes which woud


When you create multiple copies it creates fields with all the same properties (including scripts) as the original, except for the field name, which it adds a numbered suffix to.