Skip to main content
Participating Frequently
March 5, 2018
Answered

1 Button that timestamps the next empty time field?

  • March 5, 2018
  • 2 replies
  • 954 views

I'm not really sure if I am asking this correctly.  I know very little about javascript.   I created a pdf form that is used by officers to track daily tasks in relation to a certain project.  There are several lines- each line a different task or action. 

Example:

Each row has a start and stop time.

I know how to create a button that will put a timestamp in a field.   There are 24 rows in this sheet, so to do it the way I know how - would be 48 buttons (one button per row for start, one button per row for stop). That's a lot of buttons and a lot of real estate on my form, even if the buttons are tiny.

Is there a way to have a button that timestamps the next empty time field? I am not sure that makes sense, but have like 1 button that when clicked - puts the current time in the next "not null" time field?

Thank you.

This topic has been closed for replies.
Correct answer try67

Yes, it's possible. Let's say the fields are called Text1, Text2, etc. up to Text48.

You can use this code to do it:

for (var i=1; i<=48; i++) {

    var f = this.getField("Text"+i);

    if (f.valueAsString=="") {

          f.value = util.printd("HH:MM", new Date());

          break;

    }

}

2 replies

Participating Frequently
March 7, 2018

I hope I don't push it too far asking another question.

If you look at my original snapshot, I have 2 columns - Activity and Location.    The fields under them are ActivityRow1, ActivityRow2, and so on - and LocationRow1, etc.

What I would like to do - is to have a combo box in the header field for each and define a list in each.  Example  for activities --  IL, OL, C1,C2, C3, C4.   

So my goal is to select a value from the drop down and have that value populate the next empty field in the column. 

I've been able to create combobox's and define the lists - but every example of the scripting I have found hasn't worked. 

Thanks!

try67
Community Expert
Community Expert
March 7, 2018

Use this code as the custom validation script of the drop-down:

for (var i=1; i<=24; i++) {

    var f = this.getField("Activity"+i);

    if (f.valueAsString=="") {

          f.value = event.value;

          break;

    }

}

Make sure to tick the option to commit the selected value immediately, under the field's Properties, Options tab.

Participating Frequently
March 7, 2018

Got it!

Is there also a way to make it revert to a value (or display a value) after you click?  Like now, if I select C3, it puts that in the next empty field - but then it still says C3 in the text of the combo box too.  If possible - I'd like it to say "Activity" after the selection is made.  I am using the buttons and boxes over top of the column headers so I'd like it to display what the column header would display as default.

Thank you so much for all of your help!

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
March 5, 2018

Yes, it's possible. Let's say the fields are called Text1, Text2, etc. up to Text48.

You can use this code to do it:

for (var i=1; i<=48; i++) {

    var f = this.getField("Text"+i);

    if (f.valueAsString=="") {

          f.value = util.printd("HH:MM", new Date());

          break;

    }

}

Participating Frequently
March 5, 2018

That's awesome!  Thank you so much!

I actually made 2 buttons and replaced by headers "start" and "stop"  with buttons "start" and "stop" and named my fields start1, start2, etc and stop1, stop2, etc. and adjusted the count to 24 since each button is only responsible for half.  That just saved me and my team a lot of time trying to time in times.  Thank you!

try67
Community Expert
Community Expert
March 5, 2018

That's a good approach!