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)

By andreasml - July 3 - edited: July 3

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

By kitsguru - July 11 - edited: July 11

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()

Jeff Shields