Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display Message By day and time

Status
Not open for further replies.

domitbg

Programmer
Dec 9, 2012
1
PL
Hello i got a problem i know how to make a display message by day code but i need one that for example te massage of the day will change at 10am not at midnight. I wan't to do be through monday to sunday. Thx
 
not tested, but perhaps something like this might work
Code:
[b][COLOR=#0000FF]var[/color][/b] divID [COLOR=#990000]=[/color] [COLOR=#FF0000]'#someDiv'[/color][COLOR=#990000];[/color] [i][COLOR=#9A1900]//ID of div holding the message[/color][/i]
[b][COLOR=#0000FF]var[/color][/b] messages [COLOR=#990000]=[/color] [b][COLOR=#0000FF]new[/color][/b] [b][COLOR=#000000]Array[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]"Monday"[/color][COLOR=#990000],[/color] [COLOR=#FF0000]"Tuesday"[/color][COLOR=#990000],[/color] [COLOR=#FF0000]"Wednesday"[/color][COLOR=#990000],[/color] [COLOR=#FF0000]"Thursday"[/color][COLOR=#990000],[/color] [COLOR=#FF0000]"Friday"[/color][COLOR=#990000],[/color] [COLOR=#FF0000]"Saturday"[/color][COLOR=#990000],[/color] [COLOR=#FF0000]"Sunday"[/color][COLOR=#990000]);[/color]
[b][COLOR=#0000FF]var[/color][/b] cDay [COLOR=#990000]=[/color] [COLOR=#990000]-[/color][COLOR=#993399]1[/color][COLOR=#990000];[/color]

[b][COLOR=#0000FF]var[/color][/b] displayMessage [COLOR=#990000]=[/color] [b][COLOR=#0000FF]function[/color][/b][COLOR=#990000]()[/color][COLOR=#FF0000]{[/color]
[tab][b][COLOR=#0000FF]var[/color][/b] d [COLOR=#990000]=[/color] [b][COLOR=#000000]getDay[/color][/b][COLOR=#990000]([/color] [COLOR=#993399]10[/color] [COLOR=#990000]);[/color] [i][COLOR=#9A1900]//change this if you want another hour to be the threshold[/color][/i]
[tab][b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color]d [COLOR=#990000]==[/color] cDay[COLOR=#990000])[/color] [b][COLOR=#0000FF]return[/color][/b][COLOR=#990000];[/color]
[tab]cDay [COLOR=#990000]=[/color] d[COLOR=#990000];[/color]
[tab]document[COLOR=#990000].[/color][b][COLOR=#000000]getElementById[/color][/b][COLOR=#990000]([/color]divID[COLOR=#990000]).[/color]innerHTML [COLOR=#990000]=[/color] messages[COLOR=#990000][[/color]cDay[COLOR=#990000]];[/color]
[COLOR=#FF0000]}[/color]
[b][COLOR=#0000FF]var[/color][/b] getDay [COLOR=#990000]=[/color] [b][COLOR=#0000FF]function[/color][/b][COLOR=#990000]([/color] switchTime [COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][tab]switchTime [COLOR=#990000]=[/color] [b][COLOR=#000000]parseInt[/color][/b][COLOR=#990000]([/color]switchTime[COLOR=#990000])[/color] [COLOR=#990000];[/color] [i][COLOR=#9A1900]//just in case a value like "04" is passed[/color][/i]
[tab][tab][b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color]switchTime [COLOR=#990000]>[/color] [COLOR=#993399]23[/color] [COLOR=#990000]||[/color] switchTime [COLOR=#990000]<[/color] [COLOR=#993399]0[/color][COLOR=#990000])[/color] [b][COLOR=#0000FF]return[/color][/b] [b][COLOR=#0000FF]false[/color][/b][COLOR=#990000];[/color] [i][COLOR=#9A1900]//refuse improper values; must be between 0 -23[/color][/i]
[tab][b][COLOR=#0000FF]var[/color][/b] d [COLOR=#990000]=[/color] [b][COLOR=#0000FF]new[/color][/b] [b][COLOR=#000000]date[/color][/b][COLOR=#990000]();[/color]
[tab][b][COLOR=#0000FF]var[/color][/b] day [COLOR=#990000]=[/color] d[COLOR=#990000].[/color][b][COLOR=#000000]getDay[/color][/b][COLOR=#990000]();[/color]
[tab][b][COLOR=#0000FF]var[/color][/b] hour [COLOR=#990000]=[/color] d[COLOR=#990000].[/color][b][COLOR=#000000]getHours[/color][/b][COLOR=#990000]();[/color]
[tab][b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color]hour [COLOR=#990000]<[/color] switchTime[COLOR=#990000])[/color] [COLOR=#FF0000]{[/color]
[tab][tab]day [COLOR=#990000]=[/color] day [COLOR=#990000]==[/color] [COLOR=#993399]0[/color] [COLOR=#990000]?[/color] [COLOR=#993399]6[/color] [COLOR=#990000]:[/color] day [COLOR=#990000]-[/color] [COLOR=#993399]1[/color][COLOR=#990000];[/color]
[tab][COLOR=#FF0000]}[/color]
[tab][b][COLOR=#0000FF]return[/color][/b] day[COLOR=#990000];[/color]  
[COLOR=#FF0000]}[/color]

[b][COLOR=#0000FF]var[/color][/b] myTimer [COLOR=#990000]=[/color] [b][COLOR=#000000]setInterval[/color][/b][COLOR=#990000]([/color] displayMessage[COLOR=#990000],[/color] [COLOR=#993399]60000[/color] [COLOR=#990000]);[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top