0

I've got an input using the datepicker tool from jQuery. what i am trying to do is that user has to select different date formats by which he can input the dates 1) daily 2) weekly 3) yearly

how can i select different format on change? the problem is that if one format is selected it is not changing to another

  if (data == "Daily")
                {
                    alert("abc");
                    $(".sysDateFields").datepicker();
                }
                else if (data == "Weekly")
                {
                }
                else if (data == "Monthly") 
                {
                    alert("abc1");
                    $(".sysDateFields").datepicker({
                        changeMonth: true,
                        changeYear: true,
                        showButtonPanel: true,
                        dateFormat: 'MM yy',
                        onClose: function (dateText, inst) {
                            var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
                            var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
                            $(this).datepicker('setDate', new Date(year, month, 1));
                        }
                    });
                }
Oscar Fanelli
  • 3,337
  • 2
  • 28
  • 40
maztt
  • 12,278
  • 21
  • 78
  • 153

2 Answers2

0

Once you changed the format try to referesh the data picker.

$( ".sysDateFields" ).datepicker("refresh");
Raja Sekar
  • 2,062
  • 16
  • 23
0

You can simply use $('#datepicker').datepicker({ dateFormat: 'dd-mm-yy' });

And than you can change it with:

$('#datepicker').datepicker(
    'option', 'dateFormat', 'mm-dd-yy'
);

Also look here: https://stackoverflow.com/a/1328040/1668849

Community
  • 1
  • 1
Oscar Fanelli
  • 3,337
  • 2
  • 28
  • 40