I have the following code that represents a company office hours. I am trying to understand the array of var sunday_hours = new Array(). When I try to change the variables in the array it doesn’t seem to update the office hours on the display. Can anyone help me understand this?
function validateresult() {
jQuery.post('',
jQuery("#appointmentid").serialize(),
function(responseText) {
document.getElementById("formstatus").innerHTML=responseText;
if(responseText.search('success')>-1){
document.appointmentform.reset();
}
});
}
var sunday_hours = new Array(
'10',
'20',
'',
'',
'on',
'12'
);
var monday_hours = new Array(
'11',
'20',
'15',
'',
'',
'12'
);
var tuesday_hours = new Array(
'11',
'20',
'15',
'',
'',
'12'
);
var wednesday_hours = new Array(
'11',
'20',
'15',
'',
'',
'12'
);
var thursday_hours = new Array(
'10',
'20',
'',
'',
'',
'12'
);
var friday_hours = new Array(
'10',
'20',
'',
'',
'',
'12'
);
var saturday_hours = new Array(
'',
'',
'',
'',
'',
''
);
var calander_business_hours = new Array(monday_hours,tuesday_hours,wednesday_hours,thursday_hours,friday_hours,saturday_hours,sunday_hours);
//get the working hours when selected any date on the calendar
function onSelectCalendarDate(dateText, inst) {
var date;
if(dateText == '')
date = new Date();
else
date = jQuery("#widgetdateselect").datepicker('getDate');
var dayOfWeek = date.getUTCDay();
var applicable_hours = calander_business_hours[dayOfWeek];
if(applicable_hours[1] == '')
applicable_hours[1] ='0';
if(applicable_hours[2] == '')
applicable_hours[2] ='0';
if(applicable_hours[3] == '')
applicable_hours[3] ='0';
var start_hours = parseInt(applicable_hours[0]);
var close_hours = parseInt(applicable_hours[1]);
var start_mins = parseInt(applicable_hours[2]);
var close_mins = parseInt(applicable_hours[3]);
var closed = applicable_hours[4];
var format = applicable_hours[5];
var options_str = ''; //stores options of the hours
//handle 24 or 12 hours
if(format == 24){
//handle exceptional cases like close time more than midnight 12
if(close_hours < start_hours)
close_hours = 24;
loop_index = 0;
while(start_hours <= close_hours) {
start_hours = (start_hours < 10 ? '0' : '') + start_hours
if(loop_index++ == 0) {
if(start_mins == 0) options_str +='<option value="'+start_hours+':00">'+start_hours+':00</option>';
if(start_mins <= 15) options_str +='<option value="'+start_hours+':15">'+start_hours+':15</option>';
if(start_mins <= 30) options_str +='<option value="'+start_hours+':30">'+start_hours+':30</option>';
if(start_mins <= 45) options_str +='<option value="'+start_hours+':45">'+start_hours+':45</option>';
start_hours++;
continue;
}
if(start_hours == close_hours) {
if(close_mins > 0) options_str +='<option value="'+start_hours+':00">'+start_hours+':00</option>';
if(close_mins > 15) options_str +='<option value="'+start_hours+':15">'+start_hours+':15</option>';
if(close_mins > 30) options_str +='<option value="'+start_hours+':30">'+start_hours+':30</option>';
} else {
options_str +='<option value="'+start_hours+':00">'+start_hours+':00</option>';
options_str +='<option value="'+start_hours+':15">'+start_hours+':15</option>';
options_str +='<option value="'+start_hours+':30">'+start_hours+':30</option>';
options_str +='<option value="'+start_hours+':45">'+start_hours+':45</option>';
}
start_hours++;
}
}
else
if(format == 12){
//handle exceptional cases like close time more than midnight 12
if(close_hours < start_hours)
close_hours = 24;
loop_index =0;
while(start_hours <= close_hours) {
am_or_pm = start_hours - 12 >= 0? 'PM':'AM';
if(start_hours>12) {
hours_label = start_hours - 12;
}else{
hours_label = start_hours
}
hours_label = (hours_label < 10 ? '0' : '') + hours_label;
if(loop_index++ == 0) {
if(start_mins == 0) options_str +='<option value="'+hours_label+':00'+am_or_pm+'">'+hours_label+':00'+am_or_pm+'</option>';
if(start_mins <= 15) options_str +='<option value="'+hours_label+':15'+am_or_pm+'">'+hours_label+':15'+am_or_pm+'</option>';
if(start_mins <= 30) options_str +='<option value="'+hours_label+':30'+am_or_pm+'">'+hours_label+':30'+am_or_pm+'</option>';
if(start_mins <= 45) options_str +='<option value="'+hours_label+':45'+am_or_pm+'">'+hours_label+':45'+am_or_pm+'</option>';
start_hours++;
continue;
}
if(start_hours == close_hours) {
if(close_mins > 0) options_str +='<option value="'+hours_label+':00'+am_or_pm+'">'+hours_label+':00'+am_or_pm+'</option>';
if(close_mins > 15) options_str +='<option value="'+hours_label+':15'+am_or_pm+'">'+hours_label+':15'+am_or_pm+'</option>';
if(close_mins > 30) options_str +='<option value="'+hours_label+':30'+am_or_pm+'">'+hours_label+':30'+am_or_pm+'</option>';
} else {
options_str +='<option value="'+hours_label+':00'+am_or_pm+'">'+hours_label+':00'+am_or_pm+'</option>';
options_str +='<option value="'+hours_label+':15'+am_or_pm+'">'+hours_label+':15'+am_or_pm+'</option>';
options_str +='<option value="'+hours_label+':30'+am_or_pm+'">'+hours_label+':30'+am_or_pm+'</option>';
options_str +='<option value="'+hours_label+':45'+am_or_pm+'">'+hours_label+':45'+am_or_pm+'</option>';
}
start_hours++;
}
}
jQuery('#appointmenttime').find('option').remove().end().append(options_str);
jQuery("#appointmenttime").val('10:00AM');
jQuery("#appointmenttime2").val('10:00AM');
jQuery('#appointmenttime2').find('option').remove().end().append(options_str);
if(closed=='on') {
jQuery('#appointmenttime_para').hide();
jQuery('#appointmenttime_closed_para').show();
} else {
jQuery('#appointmenttime_para').show();
jQuery('#appointmenttime_closed_para').hide();
}
}
jQuery(document).ready(function() {
jQuery("#widgetdateselect").datepicker({
dateFormat: "yy-mm-dd",
minDate: 0,
//dayNamesMin : [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
//monthNames: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
firstDay:0,
altField: "#dateselect",
defaultDate: '2013-02-08', onSelect: onSelectCalendarDate
});
onSelectCalendarDate('2013-02-08',jQuery("#widgetdateselect").datepicker());
jQuery("#specialist").val('');
});