Jump to content

JS: Automatically insert the current date/time into a field

Recommended Posts

JavaScript Solution: Automatically insert the current date and time into a field

Feature Description:
This JavaScript solution will grab the local date and time from the user's computer and automatically insert it into a field named TimeofView in your Caspio Bridge DataPage. Format of date and time is set to m/d/yyyy hh:mm

This solution can be used "as-is", without any changes if
a. It is used in an Update Form or Details page of a Search and Report DataPage and
b. The name of the field storing the local date and time is called TimeofView.

To use this solution copy and paste the code below, inside the HTML Footer section of the Details page of the DataPage using the Caspio Bridge DataPage Wizard.




 /* Declaration and initialization */
 Stamp = new Date();
 var v_TimeStamp;
 Hours = Stamp.getHours()
 Mins = Stamp.getMinutes();

 /* Attach a prefix with digit '0' if the minutes is less than 10. */
 if (Mins < 10) {
   Mins = "0" + Mins;
 /* Construct the value of the v_TimeStamp variable in the format m/d/yyyy hh:mm */
 v_TimeStamp=('' + (Stamp.getMonth() + 1) +"/"+Stamp.getDate()+ "/"+Stamp.getFullYear() + ' ' + Hours + ":" + Mins);

 /* Field name - TimeofView is referred with a prefix - EditRecord */


To use this script in a Submission Form, change "editrecord" to "insertrecord" so modify the last line of code from




Additional Considerations

  • To use this script with a field not named as TimeofView, change all occurrences of the text TimeofView in the script to the appropriate field name.
  • The accuracy of the date and time stamped is dependent on the date and time set on the user's local computer.
  • The script does not take into account the time zone in which the date and timestamp are created.

Tested Browsers
This JavaScript solution was tested on the following platforms and Internet Browsers only.
# MS Windows - IE 8.0, Firefox 3.5.7, Chrome, Safari 4.0.3
# Macintosh - Firefox 3.5.7, Safari 4.0.3

Disclaimer: Use these JavaScript solutions at your own risk! They are provided to assist you in the customization of your programs and while we believe they work properly, by using them you accept all responsibility about them and confirm that they are not a feature of Caspio's platforms and as such are provided "as is" without any warranties, support or guarantees.

Link to post
Share on other sites
This topic is now closed to further replies.
  • Create New...