I have dynamically added datepicker textboxes of id's TrainingPeriodStart[]
and TrainingPeriodEnd[]
. I need to target each pair to set their proper start and end date.
The setting of the start and end date is found on the documentation link here.
I have the code below in mind but it does not work:
var inputName = '';
var number = '';
$('input[id^="TrainingPeriodStart"]').click(function() {
inputName = $(this).attr('id');
number = inputName.substr(inputName.length - 3); // get [number]
}).datepicker({
changeYear: true,
changeMonth: true,
dateFormat: 'yy-mm-dd',
onSelect: function( selected ) {
$('#TrainingPeriodEnd'+number).datepicker( "option", "minDate",
selected )
}
});
$('input[id^="TrainingPeriodEnd"]').click(function() {
inputName = $(this).attr('id');
number = inputName.substr(inputName.length - 3); // get [number]
}).datepicker({
changeYear: true,
changeMonth: true,
dateFormat: 'yy-mm-dd',
onSelect: function( selected ) {
$('#TrainingPeriodStart'+number).datepicker( "option", "maxDate",
selected )
}
});
Basically I want to target datepicker pairs with their [number]
attribute and setting their minimum and maximum dates to restrict the user from selecting illegal date ranges.
How do I solve this?