0

i want month and year seperate from this month/year picker. i tried this.

i want to insert month and year to database,for that i want it seperate.i am using codeigniter frame work

var month= $("#ui-datepicker-div .ui-datepicker-month :selected").val();
        window.write(' month');

its not working.

<!--<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">-->
<script src="../monthyear/jquery-ui.js"></script>
<link rel="stylesheet" href="jquery-ui.css">
<label for="monthYearPicker">Date :</label>
<div class="monthYearPicker" name="myDate" ></div>
<!--<input name="myDate" class="monthYearPicker" />-->
     <script>  
$(document).ready(function () {
    $(function () {
        $('.monthYearPicker').datepicker({
            changeMonth: true,
            changeYear: true,
            showButtonPanel: true,
            dateFormat: 'MM yy'
        }).focus(function () {
            var thisCalendar = $(this);
            $('.ui-datepicker-calendar').detach();
            $('.ui-datepicker-close').click(function () {
                var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
                var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
                thisCalendar.datepicker('setDate', new Date(year, month, 1));
            });
        });
    });
});
</script>
<style>
    .ui-datepicker-calendar {
   visibility:hidden;
}</style>
Umair M
  • 10,298
  • 6
  • 42
  • 74
manjusha
  • 113
  • 4
  • 6
  • 15

1 Answers1

0

Use onClose() method of datepicker.

onClose: function(dateText) { 
           dateVariable = dateText;
           if(dateVariable != null && dateVariable != ""){
                var arr = dateVariable.split(' ');
                $('#month').val(arr[0]);
                $('#year').val(arr[1]);
           }

EXAMPLE : jsFiddle

I hope this will solve your problem.

Ankur Mahajan
  • 3,396
  • 3
  • 31
  • 42