I tried to use the javascript provided. But it shows as military time. The field does not hold when sending it to Laserfiche also. Anyway help on how to modify a field to show the date and time of a signature?
Question
Question
Replies
Hello Chynna,
I know I am late to the response here...this is how we solved it:
else if (d.getHours() == 12) { var a = "PM";}
else (d.getHours() > 12) { var a = "PM"; hours = hours - 12;}
$(document).ready(function () { $('.signature').click(timestamp); function timestamp() { var d = new Date(); var minutes = d.toLocaleTimeString(); if (minutes < 10) {var minutes = "0" + minutes;} if (d.getHours() < 12) { var a = "AM";} else {var a = "PM";} if ($(this).hasClass('signature')) { $('.timesign input').val(d.getHours() + ":" + minutes + a); } } });
Update....I used w3schools to find this script. However, I am stuck with this now. I know this has to be a simple fix.
Hi Chynna,
The time you are looking for in your above example (2:12:47 PM) is sandwiched between the additions you made ("14"+":"+minutes+"PM"). Your "minutes" variable is all you need, which comes from the ".toLocaleTimeString()" method.
Also, your "if" statement is true when the clicked element has the "signature" class. However, the function only runs if an element with the "signature" class is clicked, so the "if" statement is not necessary. Try out the following JavaScript:
$(document).ready(function(){ $('.signature').on('click', function(){ var d = new Date(); $('.timesign input').val(d.toLocaleTimeString()); }); });
You can also get the current date using ".toLocaleDateString()", and a combination of the two using ".toLocaleString()". More information can be found here, however you can get the current date by using a "Date" field and setting the default value to "Today".
Also, fields that are set to "Read-only" from the form layout page are not sent to Laserfiche if their values are set by JavaScript. You can instead set the fields to read only using JavaScript:
$('.readOnly input').prop('readOnly', true);
Let me know if this works for you!