Set date on submit

If a form is sent, the current date will set.

This example shows how to set the current date. If you push the button the form will not sent, because the onsubmit funtion returns false.

$.xutil.onsubmit = function(valid) {
    var currDate = new Date(); // current client date when you send the form
    $('[name="tfDateTime"]').val(getDateFormat(currDate));
    $('[name="tfDate"]').val($.datepicker.formatDate("dd.mm.yy", currDate));
    
    return false; // have to be the value valid, otherwise the form will not sent
}

 

function getDateFormat(date){
    var day = prependNull(date.getDate());
    var month = prependNull(date.getMonth()+1);
    var year = date.getFullYear();
    var time = date.getHours()+':'+date.getMinutes();
    
    return day+'.'+month+'.'+year+' '+time;
}

 

function prependNull(value) {
    return value < 10 ? '0'+value : value;
}