How to Auto-Populate Today's Date in Date Field

Permalink Browser Info Environment
This may be second nature to many, but I'm having difficulty trying to get the Date field on an Advanced Form to automatically enter the current day's date when the form is displayed. It does include a drop-down calendar if anyone wants to make a change, but that's not even necessary, since the Date simply notes the date of data submission.

There is a "Default Value" field in the form setup (see image attached), but no examples or instruction in the documentation, and nothing I put in seems to work. Any help greatly appreciated.

1 Attachment

Type: Discussion
Status: In Progress
Empraxis
View Replies:
atsdenver replied on at Permalink Reply
atsdenver
I'm in the same boat here :-) If anyone can lend a hand?
wizardontherun replied on at Permalink Reply
wizardontherun
Looking to do the same thing, need default date to be todays date.

Frank
unionsystems replied on at Permalink Reply
unionsystems
I was able to achieve this by adding a HTML block before the advanced form block with the following code

<script type="text/javascript">
$(document).ready(function() { 
var today = new Date();
today = (today.getDate()+1)+"/"+(today.getMonth()+1)+"/"+today.getFullYear();
document.getElementById("sem-field-107").value=today;
 });
</script>


Note the line

today = (today.getDate()+1)+"/"+(today.getMonth()+1)+"/"+today.getFullYear();


is assembling in european day month year sequence. You also have to change sem-field-107 to match the id of the date field in your particular form.

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.