...

View Full Version : Disable LiveChat code based on day, time and need to add holiday dates



jschrader
12-08-2009, 11:43 PM
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:



<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

Philip M
12-09-2009, 09:50 AM
A bit vague, but in principle you need:-


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.

jschrader
03-22-2010, 07:58 AM
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



<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>

Philip M
03-22-2010, 09:56 AM
Glad that you eventually got it working! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum