I have a bootstrap date picker that has a multidate function and I want to count the number of days selected on change but it doesn't only return the present value but also the previous value. Slicing and Trimming don't work apparently.
The Code I'm using to alert the datecount
$(document).on('change', '#leavedate', function (e){
e.preventDefault();
const date = $('#leavedate').val();
const datelength = date.length;
alert(datelength);
})
CodePudding user response:
Use the javascript split() function and split the value by comma (,) then you'll get the array of dates then you can get the length of the array.
$(document).on('change', '#leavedate', function (e) {
e.preventDefault();
const date = $('#leavedate').val();
const datelength = date != '' ? date.split(',').length : 0;
alert(datelength);
});