SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help to understand date picker code

    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?


    PHP Code:
        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(dateTextinst) {

            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 == 0options_str +='<option value="'+start_hours+':00">'+start_hours+':00</option>';
                        if(
    start_mins <= 15options_str +='<option value="'+start_hours+':15">'+start_hours+':15</option>';
                        if(
    start_mins <= 30options_str +='<option value="'+start_hours+':30">'+start_hours+':30</option>';
                        if(
    start_mins <= 45options_str +='<option value="'+start_hours+':45">'+start_hours+':45</option>';
                        
    start_hours++;
                        continue;
                    }
                    if(
    start_hours == close_hours) {
                        if(
    close_mins 0options_str +='<option value="'+start_hours+':00">'+start_hours+':00</option>';
                        if(
    close_mins 15options_str +='<option value="'+start_hours+':15">'+start_hours+':15</option>';
                        if(
    close_mins 30options_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 == 0options_str +='<option value="'+hours_label+':00'+am_or_pm+'">'+hours_label+':00'+am_or_pm+'</option>';
                        if(
    start_mins <= 15options_str +='<option value="'+hours_label+':15'+am_or_pm+'">'+hours_label+':15'+am_or_pm+'</option>';
                        if(
    start_mins <= 30options_str +='<option value="'+hours_label+':30'+am_or_pm+'">'+hours_label+':30'+am_or_pm+'</option>';
                        if(
    start_mins <= 45options_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 0options_str +='<option value="'+hours_label+':00'+am_or_pm+'">'+hours_label+':00'+am_or_pm+'</option>';
                        if(
    close_mins 15options_str +='<option value="'+hours_label+':15'+am_or_pm+'">'+hours_label+':15'+am_or_pm+'</option>';
                        if(
    close_mins 30options_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"
                
    minDate0,
                
    //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',            onSelectonSelectCalendarDate
            
    });
                    
    onSelectCalendarDate('2013-02-08',jQuery("#widgetdateselect").datepicker());
                    
    jQuery("#specialist").val('');
        }); 

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    I just scanned the code and I couldn't see any obvious errors or reasons why this wouldn't work.
    If you can post a link to a page where I can see the error for myself, then I don't mind taking a closer look.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •