Reputation: 6612
I have these elements on the page (a hidden field next to a simple textbox):
<input id="start_date" type="text">
<input id="start_date_hidden" type="hidden">
I apply datePicker to textbox I wrote this :
$("#start_date").datetimepicker({
dateFormat: 'DD dd MM yy'
});
Now I want after select a date convert selected date to another format and set into hidden field. for that i wrote this :
$("#start_date").datepicker({
dateFormat: 'DD dd MM yy',
onSelect: function ( dateText, inst) {
val = $(this).datepicker({ dateFormat: 'dd-mm-yy' }).val()
$(this).next().val(val)
}
});
But this does not work and set date with same format of textbox.
How Can I do that ?
Upvotes: 0
Views: 438
Reputation: 14520
jQuery UI Datepicker supports an "alt" field and format where you can save the selected date in another format.
$("#start_date").datepicker({
dateFormat: 'DD dd MM yy',
altFormat: 'dd-mm-yy',
altField: "#start_date_hidden"
});
http://api.jqueryui.com/datepicker/#option-altField
Upvotes: 1