Carlota
Carlota

Reputation: 1237

JQuery datepicker display month dropdown changeMonth

I work with jquery jquery-1.9.1.min.js. I have the following jsp with a datepicker

<script type="text/javascript">

      $( function() {
            $( "#datepicker1" ).datepicker({
              changeMonth: true,
              changeYear: true,
              defaultDate: new Date('2016','11','02'),
            setDate: new Date('2016','11','02')
            });
          } );

</script>
</head>
<body>
    <%@include file="../menu/cabeceraMenu.jsp"%>
    <%@include file="../menu/opcionesEncuesta.jsp"%>
    <form action="${pageContext.request.contextPath}/encuesta/nueva"
        name="frm" id="nueva-encuesta" method="post" style="margin: 0px;">
        <table class="tablaCentral">
            <tr>
        <td>
        Date: <input type="text" id="datepicker1">
        </td>
        </tr>
        </table>

</body>
</html>

This is the output screen

enter image description here

How can I display the month name and number year in the screen dropdrown boxes . Now they are empty.

Date is new Date('2016','11','02') I want to set boxes with November and 2016

Upvotes: 0

Views: 1234

Answers (1)

Charantej Golla
Charantej Golla

Reputation: 598

Try after removing defaultDate and setDate.

$( function() {
    $( "#datepicker1" ).datepicker({
      changeMonth: true,
      changeYear: true
    });
  });
<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<input type="text" id="datepicker1">

Upvotes: 2

Related Questions