How can you run jqery datepicker function in Struts?
I would like to trigger an event in the jquery datepicker, but when I select a specific date, it doesn't fire.
This is my code for checking date and date, what should I do to activate this function?
$("#fromDate").datepicker({
numberOfMonths: 1,
onselect: function (selected) {
alert("hello");
var dt = new Date(selected);
dt.setDate(dt.getDate() + 1);
$("#toDate").datepicker("option", "minDate", dt);
}
});
$("#toDate").datepicker({
numberOfMonths: 1,
onselect: function (selected) {
var dt = new Date(selected);
dt.setDate(dt.getDate() - 1);
$("#fromDate").datepicker("option", "maxDate", dt);
}
});
+3
source to share
2 answers
It works as you expected with jQuery-ui datepicker
var $from = $("#fromDate"),
$to = $("#toDate");
$from.datepicker({
numberOfMonths: 1,
onSelect: function(selected) {
alert("hello");
var dt = new Date(selected);
dt.setDate(dt.getDate() + 1);
$to.datepicker("option", "minDate", dt);
}
});
$to.datepicker({
numberOfMonths: 1,
onSelect: function(selected) {
var dt = new Date(selected);
dt.setDate(dt.getDate() - 1);
$from.datepicker("option", "maxDate", dt);
}
});
<link href="http://code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.3/jquery-ui.min.js"></script>
<input type="text" id="fromDate" />
<input type="text" id="toDate" />
+1
source to share