0

i have to inputs that i want to format in an easy to read format, however when the user selects the date, i need the output to be in a format that mysql can handle. i dont think i can change the view format independantly from the output format. so im trying to achieve what i want by using hidden input elements and alt field in timepicker but i seem to be missing something. is there a better way of doing this or am i on the right track, i can't seem to get it to work.

$('.startDate').datetimepicker({
    timeFormat  : "hh:mm tt",
    separator: ' ',
    showTimezone: false,
    altField: ".startDateHidden",
    altFieldTimeOnly: false,
    altFormat: "yy-mm-dd",
    altTimeFormat: "h:m t",
    altSeparator: " "
});

$('.endDate').datetimepicker({
    timeFormat  : "hh:mm tt",
    separator: ' ',
    showTimezone: false,
    altField: ".endDateHidden",
    altFieldTimeOnly: false,
    altFormat: "yy-mm-dd",
    altTimeFormat: "h:m t",
    altSeparator: " "
});

$('.startDate, .endDate, .startDateHidden, .endDateHidden').datetimepicker('setDate', (new Date()) );

EDIT: well later in my code i make a call to the hidden fields to use the dates in an ajax call, but the getDate is returning empty for the hidden elements, being var date3 and date4

var date1 = $('.startDate').datetimepicker('getDate');
var date2 = $('.startDate').datetimepicker('getDate');
var date3 = $('.startDateHidden').datetimepicker('getDate');
var date4 = $('.endDateHidden').datetimepicker('getDate');
console.log(date1);
console.log(date2);
console.log(date3);
console.log(date4);
4

1 回答 1

0

原来我确实忽略了一些东西。

我完全忘记了隐藏的输入不是由 datetimepickers 发起的,所以我必须使用 jquery 和 val() 手动获取值

var date3 = $('.startDateHidden').val();
var date4 = $('.endDateHidden').val();
于 2013-08-09T21:35:52.630 回答