I'm helping a buddy out that runs a restaurant. What we're trying to do is develop an offline menu board using HTML and Javascript. I just can't seem to get it to work right.
Eventually, we'd like to be able to code a Mon - Sun calendar that has different menu's appearing at certain times throughout the week. But for right now, I'd like some help getting this particular code working. It would be easiest if I could get the time in an hour and minute military time, which is what I'm attempting here.Code:<title>Untitled Document</title> <script type="text/javascript"> function pixTimeChange() { var t=new Date(); var h = t.getHours(); var m = t.getMinutes(); var r1="daytime/1.jpg"; var r2="nighttime/1.jpg"; var el=document.getElementById('myimage'); var time = h + m; // See the time below. Note: The time is in 24 hour format. // In the example here, "7" = 7 AM; "17" =5PM. el.src = (time>="1159" && time<"0500") ? r1 : r2; if(time=="1159") //Change this to whatever time you want location.reload(); if(time=="0500") //Change this to whatever time you want location.reload(); } // Multiple onload function created by: Simon Willison // http://simonwillison.net/2004/May/26/addLoadEvent/ function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { if (oldonload) { oldonload(); } func(); } } } addLoadEvent(function() { pixTimeChange(); }); </script> </head> <body> <img src="" id="myimage" alt="time of day" name="menu" width="1920" height="1080"> </body> </html>
Any help would be much appreciated.
Thanks in advance!


Reply With Quote

Bookmarks