JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://code.jquery.com/ui/1.11.3/jquery-ui.min.js"></script>
<input type="text" id="TextBox1" /> <input type="text" id="TextBox2" /> Difference :
<input type="text" id="TextBox3" />
JavaScript
//Inserted function - modified from http://stackoverflow.com/questions/2536379/difference-in-months-between-two-dates-in-javascript/2536445#2536445
function monthDiff(d1, d2) {
var months;
months = (d2.getFullYear() - d1.getFullYear()) * 12;
d1m = d1.getMonth() + 1;
d2m = d2.getMonth() + 1;
months = months - d1m + d2m;
return months <= 0 ? 0 : months;
}
$("#TextBox1").datepicker({
minDate: 0,
maxDate: '+1Y+6M',
onSelect: function (dateStr) {
var min = $(this).datepicker('getDate'); // Get selected date
$("#TextBox2").datepicker('option', 'minDate', min || '0'); // Set other min, default to today
}
});
$("#TextBox2").datepicker({
minDate: '0',
maxDate: '+1Y+6M',
onSelect: function (dateStr) {
var max = $(this).datepicker('getDate'); // Get selected date
$('#datepicker').datepicker('option', 'maxDate', max || '+1Y+6M'); // Set other max, default to +18 months
var start = new Date($("#TextBox1").datepicker("getDate")); //changed line
var end = new Date($("#TextBox2").datepicker("getDate")); //changed line
var md = monthDiff(start,end); //changed line
$("#TextBox3").val(md); //changed line
}
});