Usually the datePicker
is an element to select dates. Another thing is that you want to update it from another input (which would be something strange but good, everything is possible).
If you want to retrieve the selected date, you have to create a datepicker
function in onSelect
, which will receive the parameter date from the same element.
For example:
$("#myDatePicker").datepicker({
/*Formato deseado en la salida*/
dateFormat: "yy-mm-dd",
onSelect: function (date) {
console.log(date);
}
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<p>Fecha: <input type="text" id="myDatePicker" readonly /></p>
EDITION
Let's see something similar to what you say you have: a table where for each cell there is a specific date.
If the information is in the id
of each cell (or elsewhere). It does not make any sense to open a datepicker
to select something you already know.
This code shows you how to click on any cell you get the value that is in its attribute id
. You can work with that value, without having to force the user to set the date again. In this case, your own table performs the same function as a datepicker
would:
document.querySelectorAll(".table td").forEach(function(elem) {
elem.addEventListener('click', getDate, false);
});
function getDate() {
var theDate = this.id;
console.log(theDate);
alert(theDate);
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.2/css/bulma.min.css" rel="stylesheet" />
<table class="table is-bordered">
<tr>
<td id="20180101">1</td>
<td id="20180102">2</td>
<td id="20180103">3</td>
<td id="20180104">4</td>
<td id="20180105">5</td>
</tr>
</table>