A.B.Developer A.B.Developer - 6 months ago 6x
Javascript Question

get date from datepicker in default format and convert to another format in jquery UI

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 :

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 :

dateFormat: 'DD dd MM yy',
onSelect: function ( dateText, inst) {
val = $(this).datepicker({ dateFormat: 'dd-mm-yy' }).val()


But this does not work and set date with same format of textbox.

How Can I do that ?


jQuery UI Datepicker supports an "alt" field and format where you can save the selected date in another format.

    dateFormat: 'DD dd MM yy',
    altFormat: 'dd-mm-yy',
    altField: "#start_date_hidden"