CosminV of Technical Support
11/11/2019 - 8:30 AM

Add current date in hidden field.

Add current date in hidden field.

Example: http://adddateinfield.pagedemo.co/

<!-- START code current date to hidden field -->
<!-- format DD/MM/YYYY -->
<script>
document.addEventListener("DOMContentLoaded", function() {  
    var fieldName = "date";
        var getDate = function () {

            var dateObject = new Date(),
                disp = [];
 
            disp.push(dateObject.getDate().toString());
            
            if(dateObject.getMonth() < 9) {
                disp.push( '0' + (dateObject.getMonth() + 1).toString() );
            } else {
                disp.push( (dateObject.getMonth() + 1).toString() );
            }
            
            disp.push(dateObject.getFullYear().toString());
            
            return disp.join( '/' );
        }; //getDate()
 
        document.querySelector('input[name="'+ fieldName +'"]').value = getDate();         
           
}); // ready
</script>
<!-- END code current date to hidden field -->
<!-- START code current date to hidden field -->
<script>
document.addEventListener("DOMContentLoaded", function() {   
     var fieldName = "date";
        var date = function () {
            var dateObject = new Date();
            var disp = [];
            var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

            disp.push(monthNames[dateObject.getMonth()]);
            disp.push(dateObject.getDate());
            disp.push(dateObject.getFullYear());
            
            return disp.join( ' ' );
        }; //function

        document.querySelector('input[name="'+ fieldName +'"]').value = date();           
}); // ready
</script>
<!-- END code current date to hidden field -->