I am working on an asp.net mvc-4 web application . and i have three fields inside my view:-
-Live Date (populated with jQuery DatePicker) -End Date -Length In Months
<input Value="31/05/2016" class="datepicker" data-val="true" data-val-date="The field Live Date must be a date." id="LiveDate" name="LiveDate" type="text" value="31/05/2016 00:00:00" />
<input Value="31/10/2016" class="datepicker" data-val="true" data-val-date="The field End Date must be a date." disabled="disabled" id="EndDate" name="EndDate" type="text" value="31/10/2016 00:00:00" />
<input class="text-box single-line" data-val="true" data-val-number="The field Contract Length (In Months) must be a number." data-val-required="The Contract Length (In Months) field is required." id="ContractLength" name="ContractLength" type="number" value="5" />
now i want using jQuery to perform the following:-
End Date to be equal to Live Date + Length In months.
so if a user select the date to be let say 1/1/2000 and length in month to be 3 . then the End date should be equal to 1/4/2000.. so in other word i want the end date to change if the user chnage the live date and/or length in month ... so can anyone adivce ?
EDIT:-
currently my date format for live date is dateFormat: "dd/mm/yy"
now i tried the following jquery :-
$("#LiveDate, #ContractLength").change(function () {
var st = new Date($("#LiveDate").val());
var month = $("#ContractLength").val();
$("#EndDate").val(st.getDate() + '/'+(new Date(st.setMonth(st.getMonth() + month)).getMonth() + 1) + '/' + st.getFullYear());
});
but currently if i have my livedate=31/05/2016
and my contract length = 4
, then the end date will be 5/5/2023
!!! not sure why ?