Jump to content
  • 0

Add DateTime stamp on checkbox


Duncan

Question

Hello,

I have just signed up with Caspio and am creating my first app, but have run into a hurdle I am hoping can be overcome.

The app records test cycles and I have a requirement to capture the following fields:

  1. Start Weight
  2. Start Time (DateTime)
  3. Stop Weight
  4. Stop Time (DateTime)
  5. Mass Consumed (1 - 3) [Calculated Field]
  6. Cycle Time in (decimal) hours (4 - 2) [Calculated Field]
  7. Consumption Rate (5/6) [Calculated Field]

Ideally, I would like the user to be able to click a button or checkbox to capture the date/time, as the form will need to be open when the test starts and we may need to re-start.

So, I have two questions please:

  1. On a Datapage form, is it possible to add a DateTime stamp to a field using a HTML button or checkbox and some JacaScript?
  2. Can I then calculate the difference in hours (digital...i.e. 4.5 is 4hr 30min) and add this to the cycle time field?

 

Any help would be appreciated.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Yes on can use this JS in the Footer of HTML Block below all your elements:

 

<script>
document.getElementById('InsertRecordStampCheckbox').onchange = function (){
if (document.getElementById('InsertRecordStampCheckbox').checked){
document.getElementById('InsertRecordDate').value = '[@cbTimestamp]';

} else {document.getElementById('InsertRecordDate') = '';}
};
</script>

in 'InsertRecordStampCheckbox ' you need to replace "StampCheckbox" with checkbox field name

in "InsertRecordDate" change "Date" with the date field name you want to record the timestamp

Link to comment
Share on other sites

  • 0

Hi MayMusic,

Thank you.  I have inserted a form with a checkbox and a HTML footer with the script, but it's not working. 

Here is the checkbox...

<input name="start" type="checkbox" value="start" /> Start

 

And here is what I've put in the footer HTML...

<script>
document.getElementById('start').onchange = function (){
if (document.getElementById('start').checked){
document.getElementById('Start_time').value = '[@cbTimestamp]';
} else {document.getElementById('Start_time') = '';}
};
</script>

 

Have I set this up wrong.  I've attached a couple of screenshots of the setup dialog.

Screenshot 2019-08-28 at 21.25.23.png

Screenshot 2019-08-28 at 21.25.13.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...