How to set the default value of a date field to be the value of another field?
3 posts by 3 authors in: Forums > CMS Builder
Last Post: July 11 (RSS)
Hi
I would like to set the default value of a date field (e.g., the date_2 field) to be the date of another field of the same record (e.g., the date_1 field).
Can something like the following be an option?
<?php echo htmlspecialchars($RECORD['date_1'] ?? ''); ?>
Thanks,
Andreas
Hi Andreas,
The date fields don't support PHP content, unfortunately. Also, the default values are used when a new record is created, and at that point none of the other date fields have set values yet either.
Let me know what you're trying to accomplish and I'll see if I can think of any other approaches.
interactivetools.com
You could use javascript in cmsb/custom.js. This assumes you are using date picker (on by default since 3.67).
$("input[name=date_1:mon], input[name=date_1:day], input[name=date_1:year]").on('change', function () {
var mon = $("input[name=date1:mon]").val();
var day = $("input[name=date1:day]").val();
var year = $("input[name=date1:year]").val();
$("input[name=name=date2:mon]").val(mon);
$("input[name=name=date2:day]").val(day);
$("input[name=name=date2:year]").val(year);
});
You could even do calcs on the date if you wanted it x days in the future. To limit it to a specific table you can check the "input[name=menu].val()