My code currently console.log
s the value of the variable timestamp
when the document is ready. Is there a way of running this every time the variable timestamp
is updated in the .datepicker()
function without it being in the function itself?
$("document").ready(function() {
var timestamp;
$("#startDate").datepicker({
onSelect: function(e) {
var dateAsObject = $(this).datepicker("getDate");
timestamp = dateAsObject.getTime();
console.log("user selected: " + timestamp);
return timestamp;
}
});
console.log("test: " + timestamp);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<form action="">
<label for="startDate">Select a date:</label>
<input type="text" id="startDate" name="startDate">
</form>