javascript - jQuery datepicker altFormat not displayed -


i have jquery datepicker localized based on language preferences of seller. each datepicker customization has different date format want input when form submitted in specific format parsing. trying use altformat on date picker set 'mm/dd/yy' not want date in format shown user. there way this. i.e. there way have different date formats datepicker evaluate same date when creating javascript date objects?

why not want use altformat altfield ?

in simple example here can store , access date in desired format mm/dd/yywhile showing user in "his" desired format. see jsfiddle on button click shown format changes format in altfield doesn't.

<input type="text" id="datepicker"> <input type="button" id="changeformat" value="change!"> <!-- hidden input --> <input type="text" id="altformat">  $(document).ready(function () {      $('#datepicker').datepicker({         dateformat: "dd.mm.yy",         altformat: "dd/mm/yy",         altfield: '#altformat'     });     $('#changeformat').click(function () {         //changes dateformat user sees         $('#datepicker').datepicker('option', 'dateformat', 'dd-mm-yy');         console.log($('#datepicker').datepicker('option', 'altformat'));     }); }); 

((accidentally used dd/mm/yy instead of mm/dd/yy in 1st example))

edit

this working example stores date in mm/dd/yyformat in data-altformat attribute can access with

$('#datepicker').data('altformat'); //outputs e.g. 05/31/2013 

onselect store value of currentdate in attribute doing

onselect: function () {     //gets desired format     var altformat = $(this).datepicker('option', 'altformat');     //get current date in user format     var currentdate = $(this).datepicker('getdate');     //format user format desired format     var formateddate = $.datepicker.formatdate(altformat, currentdate);     //set data-* attribute formateddate     $('#datepicker').data('altformat', formateddate);     $('#altformat').val(formateddate); } 

the advantage method don't need hidden input anymore. hope may you.

edit2

just noticed don't need new date() .datepicker('getdate')


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -