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.

Known Participant
November 29, 2024

Make sure you enable the option to show the JS Console on errors and messages (via Preferences - JavaScript). That will immediately show you when you have errors in your code when you run it.


Great, thanks - I have that selected now.

 

Am I posting the new "var" script in the wrong place? I'm putting it in the checkbox script bit.

 

I watched the video on the article you linked to but that's about calculations so I got confused again. I need to create individual duplicates of all the fields for about 40 pages. I've created ones for the name on each page which is no problem - I just duplicated them across each page - but they will always have the same values. Whereas the other text boxes will have unique values. I can't figure out where to put the script in for these boxes as the script in the checkbox is an action in response to a mouse click.