|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Looking for timed image script
Hi
I am about to help run an charity Internet radio station and ive been asked to try and get something in the form of a script working thats way out my league. Im looking for a script that will allow a different image to display on a certian time of the day for 2 hours depending what day it is and within a fortnightly period. The idea behind this is to display what dj is onair based on the fortnightly or weekly slot they have booked. Any help on this or even if someone could direct me to a script would be greatly appreciated. |
|
#2
|
|||
|
|||
|
Images with time
try the given file "sun.html" in the browser.
put the value insted of 1000 and path of images as insted of 'sun1.jpg, 'sun2.jpg', 'sun3.jpg', 'sun3.jpg', as you required in the given code file 1000 means 1 second <html> <head> <script type="text/javascript"> var q=0, k; function change() { q = q+1; k=setTimeout("change()",1000); var i = new Array("p", "sun1.jpg", "sun2.jpg", "sun3.jpg", "sun4.jpg"); document.getElementById('p').innerHTML = '<img src="'+i[q]+'" />'; if(q == 4) q = 0; } </script> </head> <body id='p' onload="change('p')"> </body> </html> |
|
#3
|
|||
|
|||
|
Thanks for the help Pprakash.
The issue i have now is this will only allow me to display an array of images on a delayed or timed loop rather than have the image load on a specific time and day within a 2 week period like a scheduled image function...is this even possible? |
|
#4
|
|||
|
|||
|
I cannot understand, please give any example
|
|
#5
|
|||
|
|||
|
ok heres the same idea only in PHP which is causing confilcts with other scripts on my page. So what I need is the same idea only in Javascript or a simplified version of the script below:-
<?php $h = date('G'); //set variable $h to the hour of the day $d = date('w'); //set variable $d to the day of the week. $year = date('Y'); //set variable $year to the current year //G is the date key for hours in 24 format (not 12), with no leading 0s, like 02. // Adjust 2 hour offset for MST below. $h = $h-2; // MONDAY SCHEDULE if ($d == 1 && $h >= 0 && $h < 18) $img = 'img/hosts/DJname.png'; else if ($d == 1 && $h >= 18 && $h < 20) $img = 'img/hosts/DJname.png'; else if ($d == 1 && $h >= 20 && $h < 22) $img = 'img/hosts/DJname.png'; else if ($d == 1 && $h >= 22) $img = 'img/hosts/DJname.png'; else if ($d == 2 && $h < 0) $img = 'img/hosts/DJname.png'; // TUESDAY SCHEDULE if ($d == 2 && $h >= 0 && $h < 18) $img = 'img/hosts/DJname.png'; else if ($d == 2 && $h >= 18 && $h < 20) $img = 'img/hosts/DJname.png'; else if ($d == 2 && $h >= 20 && $h < 22) $img = 'img/hosts/DJname.png'; else if ($d == 2 && $h >= 22) $img = 'img/hosts/FDJname.png'; else if ($d == 3 && $h < 0) $img = 'img/hosts/DJname.png'; // WEDNESDAY SCHEDULE if ($d == 3 && $h >= 0 && $h < 18) $img = 'img/hosts/Free.png'; else if ($d == 3 && $h >= 18 && $h < 20) $img = 'img/hosts/aFree.png'; else if ($d == 3 && $h >= 20 && $h < 22) $img = 'img/hosts/Free.png'; else if ($d == 3 && $h >= 22) $img = 'img/hosts/Free.png'; else if ($d == 4 && $h < 0) $img = 'img/hosts/Free.png'; // THURSDAY SCHEDULE if ($d == 4 && $h >= 0 && $h < 18) $img = 'img/hosts/DJname.png'; else if ($d == 4 && $h >= 18 && $h < 20) $img = 'img/hosts/DJname.png'; else if ($d == 4 && $h >= 20 && $h < 22) $img = 'img/hosts/DJname.png'; else if ($d == 4 && $h >= 22) $img = 'img/hosts/FDJname.png'; else if ($d == 5 && $h < 0) $img = 'img/hosts/FDJname.png'; // FRIDAY SCHEDULE if ($d == 5 && $h >= 0 && $h < 18) $img = 'img/hosts/DJname.png'; else if ($d == 5 && $h >= 18 && $h < 20) $img = 'img/hosts/DJname.png'; else if ($d == 5 && $h >= 20 && $h < 22) $img = 'img/hosts/DJname.png'; else if ($d == 5 && $h >= 22) $img = 'img/hosts/DJname.png'; else if ($d == 6 && $h < 0) $img = 'img/hosts/DJname.png'; // SATURDAY SCHEDULE else if ($d == 6 && $h >= 0 && $h < 2) $img = 'img/hosts/DJname.png'; else if ($d == 6 && $h >= 2 && $h < 4) $img = 'img/hosts/DJname.png'; else if ($d == 6 && $h >= 4 && $h < 16) $img = 'img/hosts/DJname.png'; else if ($d == 6 && $h >= 16 && $h < 18) $img = 'img/hosts/DJname.png'; else if ($d == 6 && $h >= 18 && $h < 20) $img = 'img/hosts/DJname.png'; else if ($d == 6 && $h >= 20 && $h < 22) $img = 'img/hosts/DJname.png'; else if ($d == 6 && $h >= 22) $img = 'img/hosts/DJname.png'; else if ($d == 0 && $h < 0) $img = 'img/hosts/Free.png'; // SUNDAY SCHEDULE else if ($d == 0 && $h >= 0 && $h < 16) $img = 'img/hosts/DJname.png'; else if ($d == 0 && $h >= 16 && $h < 18) $img = 'img/hosts/DJname.png'; else if ($d == 0 && $h >= 18 && $h < 20) $img = 'img/hosts/DJname.png'; else if ($d == 0 && $h >= 20 && $h < 22) $img = 'img/hosts/DJname.png'; else if ($d == 0 && $h >= 22) $img = 'img/hosts/DJname.png'; else if ($d == 1 && $h < 0) $img = 'img/hosts/Free.png'; ?> |
|
#6
|
|||
|
|||
|
I do the some modifications in your given code shown below, and observe. If u have any douts ask.
<?php $h = date('G'); //set variable $h to the hour of the day $d = date('w'); //set variable $d to the day of the week. $year = date('Y'); $s = date('s'); //set variable $year to the current year //G is the date key for hours in 24 format (not 12), with no leading 0s, like 02. // Adjust 2 hour offset for MST below. $h = $h-6; $d = $d+1; // MONDAY SCHEDULE if ($d == 1 && $h >= 0 && $h < 18) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 1 && $h >= 18 && $h < 20) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 1 && $h >= 20 && $h < 22) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 1 && $h >= 22) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 2 && $h < 0) {$img = 'img/hosts/DJname.png';echo $img;} // TUESDAY SCHEDULE if ($d == 2 && $h >= 0 && $h < 18) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 2 && $h >= 18 && $h < 20) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 2 && $h >= 20 && $h < 22) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 2 && $h >= 22) {$img = 'img/hosts/FDJname.png';echo $img;} else if ($d == 3 && $h < 0) {$img = 'img/hosts/DJname.png';echo $img;} // WEDNESDAY SCHEDULE if ($d == 3 && $h >= 0 && $h < 18) {$img = 'img/hosts/Free.png';echo $img;} else if ($d == 3 && $h >= 18 && $h < 20) {$img = 'img/hosts/aFree.png';echo $img;} else if ($d == 3 && $h >= 20 && $h < 22) {$img = 'img/hosts/Free.png';echo $img;} else if ($d == 3 && $h >= 22) {$img = 'img/hosts/Free.png';echo $img;} else if ($d == 4 && $h < 0) {$img = 'img/hosts/Free.png';echo $img;} // THURSDAY SCHEDULE if ($d == 4 && $h >= 0 && $h < 18) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 4 && $h >= 18 && $h < 20) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 4 && $h >= 20 && $h < 22) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 4 && $h >= 22) {$img = 'img/hosts/FDJname.png';echo $img;} else if ($d == 5 && $h < 0) {$img = 'img/hosts/FDJname.png';echo $img;} // FRIDAY SCHEDULE if ($d == 5 && $h >= 0 && $h < 18) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 5 && $h >= 18 && $h < 20) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 5 && $h >= 20 && $h < 22) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 5 && $h >= 22) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 6 && $h < 0) {$img = 'img/hosts/DJname.png';echo $img;} // SATURDAY SCHEDULE else if ($d == 6 && $h >= 0 && $h < 2) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 6 && $h >= 2 && $h < 4) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 6 && $h >= 4 && $h < 16) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 6 && $h >= 16 && $h < 18) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 6 && $h >= 18 && $h < 20) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 6 && $h >= 20 && $h < 22) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 6 && $h >= 22) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 0 && $h < 0) {$img = 'img/hosts/Free.png';echo $img;} // SUNDAY SCHEDULE else if ($d == 0 && $h >= 0 && $h < 16) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 0 && $h >= 16 && $h < 18) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 0 && $h >= 18 && $h < 20) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 0 && $h >= 20 && $h < 22) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 0 && $h >= 22) {$img = 'img/hosts/DJname.png';echo $img;} else if ($d == 1 && $h < 0) {$img = 'img/hosts/Free.png';echo $img;} ?> |
|
#7
|
||||
|
||||
|
Answer: Scriptaculous
|
|
#8
|
||||
|
||||
|
Simply make a php script that extracts the correct image, and call the page at certain intervals with ajax to always have the newest image up if the user doesnt refresh the page....
__________________
www.dreamsoft.no |
|
#9
|
|||
|
|||
|
How do I do that?
Would you have a script handy lol |
|
#10
|
|||
|
|||
|
This seems like a lot of coding overkill when what it looks like you need a database storing the schedule and a quick SQL call from PHP to see what image should be displayed when the page is loaded. Just saying.
|
|
#11
|
|||
|
|||
|
Sounds like a great idea and a simple one however the only thing I know about mySQL is my host provides me it lol.
Ive never wrote anything in SQL. |
|
#12
|
|||
|
|||
|
Can anyone provide me with a method for doing this i.e a script that I can copy or instructions?
My pages are .html extensions with various javascripts running on my index page. I need to be able to display an image of the DJ thats playing at a certain time and a certain day. |
|
#13
|
||||
|
||||
|
The solution to your problem is not in javascript. It can be answered using php. Simply create a php script like this:
// This script displays an specific image on each specified day and time. <?php echo "<img alt='DJ photo' src='"; $now=getdate(); if (now["mday"]==1 && now[hours]==14 && now[minutes]=32]) { echo "thisdj.jpg"; } else if (now["mday"]==1 && now[hours]==14 && now[minutes]=52]) { echo "thatdj.jpg"; } else if (now["mday"]==1 && now[hours]==15 && now[minutes]=22]) { echo "thatotherdj.jpg"; } // Ans so on. mday is the number of the day, huors and minutes are // obvious. you may use seconds too. for more information look at // http://www.php.net/manual/en/function.getdate.php // Don't forget to close the image tag! : echo "'>"; ?> |
|
#14
|
|||
|
|||
|
Alternatively you could make xml files containing the "schedule" and image URLs you plan. Then you would just need to check which schedule to match using the built in data functions in Javascript and an AJAX call to load the xml files. I get the sneaky suspicion that your DJ schedule will not be the same always and you'd need to change your series of if statements every time you needed to change the schedule. Using an XML file to store your schedule would allow you to change the schedule without having to touch the code that chooses what to display. (This would still be much easier/better using PHP and MySQL since the SQL server could return your desired image URL much more efficiently and wouldn't require browsers to have javascript available and enabled).
|
|
#15
|
|||
|
|||
|
The only problem i have though is that it cannot be in php.
My files are html and changing it to a php extension will mess other scripts up. My host wont add commands to the htaccess to allow php to display in html. So i more or less need a javascript version of any the above scripts. |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|