I'm using a jQuery-UI datePicker to generate date in an "input text" field, but I can not get the date selected in the datePicker to be set on that input and I do not understand what's wrong.
What is missing in this code so that input text From
and input text To
have their values changed?
<script src="/javascripts/jquery/jquery-1.12.4.js"></script>
<script src="/javascripts/jquery//jquery-ui.js"></script> <script>
$( function() {
var dtFormat = "dd/mm/yy",
from = $( "#from" )
.datepicker({
//defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
dateFormat: dtFormat,
altFormat: "yy-mm-dd"
})
.on( "change", function() {
to.datepicker( "option", "minDate", getDate( this ) );
}),
to = $( "#to" ).datepicker({
//defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
dateFormat: dtFormat,
altFormat: "yy-mm-dd"
})
.on( "change", function() {
from.datepicker( "option", "maxDate", getDate( this ) );
});
function getDate( element ) {
var date;
try {
date = $.datepicker.parseDate( dtFormat, element.value );
} catch( error ) {
date = null;
}
return date;
}
} );
</script>
</head>
<body>
<form class="form-horizontal well" method="post" action="/report">
<label for="from">From</label>
<input type="text" id="from" name="from">
<label for="to">To</label>
<input type="text" id="to" name="to">
<input class="button btn-default" type="submit" value="Gerar Relatório">
<table width="100%">