Take values from datepicker and use as parameter

Asked

Viewed 635 times

0

I am using Datepicker to set month and year as parameters for my search, for this I want to play them as a warning to be sure that they are being stored in the variable, but I can’t - I believe because I am in 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'],
        });
    } );

1 answer

0


You can use this

$("#monthpicker").datepicker("getDate");
  • Right, but how do you stop setting for a variable?

  • var datepicker = $("#monthpicker"). datepicker("getDate"); If possible scores the response friend.

  • Thanks Maycon, it worked!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.