2
In a project of mine, I have two fields configured as datepicker
(jQuery UI). Only the first is editable (InitialDate
). The second (FinalDate
) must have the same value as InitialDate
plus one year.
If I use the following code:
<script>
$(document).ready(function () {
$("#InitialDate").change(function () {
var d = $.datepicker.parseDate('dd/mm/yy', $(this).val());
d.setFullYear(d.getFullYear() + 1);
$('#FinalDate').datepicker('setDate', d);
});
});
</script>
the script adds wrong. The date is five days less.
Researching, I discovered that I have to modify the code for something like this:
<script>
$(document).ready(function () {
$("#InitialDate").change(function () {
var d = $.datepicker.parseDate('dd/mm/yy', $(this).val());
var year = parseInt(1, 10);
d.setFullYear(d.getFullYear() + year);
$('#FinalDate').datepicker('setDate', d);
});
});
</script>
Why?
I don’t see what’s wrong http://jsfiddle.net/bkZ4V/
– bfavaretto
The second code is exactly the same as the first, after all
parseInt(1, 10)
is always1
. What’s the difference?– Guilherme Bernal