Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Disable LiveChat code based on day, time and need to add holiday dates

    I have a javascript controlling the display of a DIV that I did a while back that needs a bit more tweaking to add function to hide the DIV on specific holidays. As it is now, by default, the DIV is being hidden unless it is M-F between 8:00AM-6:00PM:

    Code:
    <script type="text/javascript">
    onload=function(){
    	var rightNow = new Date();
    	var day = rightNow.getDay();
    	var hour = rightNow.getHours();
    	var minute = rightNow.getMinutes();
    	var formDisplay = 'none'; // unless we see otherwise
    	var forwardDisplay = 'block'; // unless we see otherwise
    	
    	if(day==1  ||  day==2  ||  day==3  ||  day==4  ||  day==5) {  // if chat is avalable on these days
        	if((hour>=8)  &&  (hour<=17)) // if chat is avalable between these times
                formDisplay = 'block', forwardDisplay = 'none';
        	}
    document.getElementById('ChatForm').style.display = formDisplay;
    document.getElementById('ChatForward').style.display = forwardDisplay;
    }
    </script>
    Im assuming that I would just add more else if statements, but not really sure the cleanest way to assign specific dates using this format.

    Any help is appreciated

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,016
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    A bit vague, but in principle you need:-

    Code:
    var rightNow = new Date();
    var day = rightNow.getDay();
    var month = rightNow.getMonth() +1;  // months are 0-11
    var dt = rightnow.getDate();  1-31
    if ((month == 12 && day == 25)) { // Christmas Day
    var formDisplay = "none";
    }
    In other words, on Christmas Day the display is not shown.

    "They (Northwich Victoria) are rattling a few of Charlton's feathers." - Football commenator.

  • #3
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    just wanted to post back to the finished script with both the holiday schedule and weekly schedule scripted. Finally got back to it and finished the first of March...
    Thanks Philip for the help!

    Had to do the holidays first and then the weekly for it to function correctly

    Code:
    <script type="text/javascript">
    onload=function(){
    
    	var rightNow = new Date();
    	var day = rightNow.getDay();
    	var month = rightNow.getMonth() +1;     // months are 0-11
    	var dt = rightNow.getDate(); // 1-31
    	var hour = rightNow.getHours();
    	var minute = rightNow.getMinutes();
    	var formDisplay = 'none';     			 // unless we see otherwise
    	var forwardDisplay = 'block';     		 // unless we see otherwise
    	
    		if ((month==1) && (day==1)) {		 			// New Years
    			var formDisplay = 'none', forwardDisplay = 'block';
    		}
    		else if ((month==1) && (day==18)) {		 			// Martin Luther King 
    			var formDisplay = 'none', forwardDisplay = 'block';
    		}
    		else if ((month==2) && (day==15)) {		 			// Presidents Day 
    			var formDisplay = 'none', forwardDisplay = 'block';
    		}
    		else if ((month==5) && (day==31)) {		 			// Memorial Day 
    			var formDisplay = 'none', forwardDisplay = 'block';
    		}
    		else if ((month==7) && (day==5)) {		 			// Independence Day 
    			var formDisplay = 'none', forwardDisplay = 'block';
    		}
    		else if ((month==9) && (day==6)) {		 			// Labor Day 
    			var formDisplay = 'none', forwardDisplay = 'block';
    		}
    		else if ((month==10) && (day==11)) {		 			// Columbus Day 
    		   	var formDisplay = 'none', forwardDisplay = 'block';
    		}
    		else if ((month==11) && (day==11)) {		 			// Veterans Day 
    		   	var formDisplay = 'none', forwardDisplay = 'block';
    		}
    		else if ((month==11) && (day==25)) {		 			// Thanksgiving
    		   	var formDisplay = 'none', forwardDisplay = 'block';
    		}
    		else if ((month==11) && (day==26)) {		 			// Day after Thanksgiving 
    		   	var formDisplay = 'none', forwardDisplay = 'block';
    		}
    		else if ((month==12) && (day==24) && (hour>=12)  &&  (hour<=17)) {		 // Christmas Eve HALF DAY
    		   	var formDisplay = 'none', forwardDisplay = 'block';
    		}
    		else if ((month==12) && (day==31) && (hour>=12)  &&  (hour<=17)) {		 // New Years Eve HALF DAY
    			var formDisplay = 'none', forwardDisplay = 'block';
    		}
    		
    		else if(day==1  ||  day==2  ||  day==3  ||  day==4  ||  day==5) {  // if chat is avalable on these days
       			if((hour>=8)  &&  (hour<=17)) 		 // if chat is avalable between these times
              	formDisplay = 'block', forwardDisplay = 'none';
        	}
    	
    document.getElementById('ChatForm').style.display = formDisplay;
    document.getElementById('ChatForward').style.display = forwardDisplay;
    }
    </script>

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,016
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Glad that you eventually got it working!


  •  

    Posting Permissions

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