Как отобразить дату, полученную из jQuery, для отображения текущей даты? У меня есть раскрывающийся список и ввод с помощью datepicker.
Теперь я делаю следующее: когда пользователь выбирает год 2019-2020
из раскрывающегося списка, я отображаю дату в поле ввода 31/03/2020
.
если выбрать 2020-2021
, то будет отображаться 31/03/2021
и так далее.
Я имею в виду, что дата и месяц фиксируются только при изменении года.
I am getting my output in the input field but when I click on the input field then it's showing the current date. I need whatever the date comes from the jquery that date auto selected.
$("#year").change(function() {
var dropdownDuration = this.value;
var items = dropdownDuration.split('-');
//alert("31/03/"+items[1]);
$("#yearDate").val("31/03/" + items[1]);
});
$("#yearDate").datepicker();
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css">
<select class="form-control" name="year" id="year">
<option value="" disabled selected>Year</option>
<option value="2019-2020">2019-2020 </option>
<option value="2020-2021">2020-2021 </option>
<option value="2021-2022">2021-2022 </option>
</select>
<input type="text" name="enddate" class="form-control datepicker" id="yearDate">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script>