I'm trying to do a small "opening hours" script in JS. I use timepicker for this and all works fine execept that I want to have a function for each days and I don't want to copy paste it seven times.
This is a part of my code : Call part :
jQuery(document).ready(function() {
var week = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
for (var i = 0; i < week.length; i++) {
day = week[i];
jQuery('#' + day + '_start1').timepicker({
showLeadingZero: false,
onHourShow: MondayHourFuncStart,
//I want to add the day name instead of Monday
onMinuteShow: MondayMinFuncStart //I want to add the day name instead of Monday
});
}
Function part :
week = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
for (var i = 0; i < week.length; i++) {
function MondayHourFuncStart(hour) //I want to add the day name instead of Monday {
var day = week[i];
var tpEndHour = jQuery('#' + day + '_end1').timepicker('getHour');
// all valid if no end time selected
if (jQuery('#monday_end1').val() == '') {
return true;
}
// Check if proposed hour is prior or equal to selected end time hour
if (hour <= tpEndHour) {
return true;
}
// if hour did not match, it can not be selected
return false;
}
So I just want to have the array value instead of "Monday"
I've try many things but I don't find the good solution.
Thanks in advance.