Get values from datepicker and use as parameter

0

I'm using the Datepicker to set month and year as parameters for my search, so I want to throw them as an alert to make sure they're being stored in the variable, but I can not - believe it to be in the onClose function. If anyone knows how to help me, follow my code:

$( function() {
        $( "#monthpicker" ).datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'MM yy',
            dateFormat: 'dd/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));
                alert(year, month);
            },
            dayNames: ['Domingo','Segunda','Terça','Quarta','Quinta','Sexta','Sábado','Domingo'],
            dayNamesMin: ['D','S','T','Q','Q','S','S','D'],
            dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sáb','Dom'],
            monthNames: ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
            monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'],
        });
    } );
    
asked by anonymous 18.04.2018 / 16:48

1 answer

0

You can use this

$("#monthpicker").datepicker("getDate");
    
18.04.2018 / 16:51