Click to See Complete Forum and Search --> : I need a JS expert on this one
Winterdragon
03-07-2003, 03:10 PM
I need to find out if it is possible to get a JavaScript code that will allow me to change an Image on a page by the DATE. Basically I have to rotate 4 images every quarter and I am looking for a script that will do this for me automatically. Any help would be appreicated.
Thanks,
Winter Dragon
Take a look at this code:
<html>
<head>
<title>Rotate images based on month</title>
<script language="javascript" type="text/javascript">
function quarterlyimg()
{
month = new Date();
month = month.getMonth();
if (month <= 2) //Jan - Mar
{
document.rotatingimg.src = "one.gif";
}
else if (month <= 5) //Apr - June
{
document.rotatingimg.src = "two.gif";
}
else if (month <= 8) //July - Sept
{
document.rotatingimg.src = "three.gif";
}
else //Oct - Dec
{
document.rotatingimg.src = "four.gif";
}
}
</script>
</head>
<body onload="quarterlyimg();">
<img src="pics/details1.gif" name="rotatingimg" border="0"/>
</body>
</html>
Winterdragon
03-07-2003, 03:55 PM
Thank you for your prompt reply. Judging from the code, it looks like that will do the trick. I will add and see.
Thanks again,
Winter Dragon
Dan Drillich
03-07-2003, 03:56 PM
The following might also help -
<script>
var s;
var now = new Date();
var m = now.getMonth();
switch (m) {
case 0,1,2:
s = "first";
break;
case 3,4,5:
s = "second";
break;
case 6,7,8:
s = "third";
break;
case 9,10,11:
s = "fourth";
break;
}
</script>
gil davis
03-07-2003, 04:05 PM
<head>
<script>
var now = new Date();
var qtr1 = new Date(now.getFullYear(), 2, 0);
var qtr2 = new Date(now.getFullYear(), 5, 0);
var qtr3 = new Date(now.getFullYear(), 8, 0);
var is_qtr1 = (now < qtr1);
var is_qtr2 = (now < qtr2) && !is_qtr1;
var is_qtr3 = (now < qtr3) && !is_qtr1 && !is_qtr2;
var is_qtr4 = !is_qtr1 && !is_qtr2 && !is_qtr2;
var imgToUse = (is_qtr1) ? "qtr1img.gif" : (is_qtr2) ? "qtr2img.gif" : (is_qtr3) ? "qtr3img.gif" : "qtr4img.gif";
</script>
</head>
<body>
<script>
document.write('<img src="' + imgToUse + '">');
</script>
</body>
Hmm... so many choices! LOL! :D
Winterdragon
03-22-2003, 03:26 PM
Is it possible to use this or a variation of this code to do the same thing but with a FLASH swf file? I've had to create 4 versions of a flash animation because of the same quaterly rotation and was wondering if this code could be modified to use verions a-d for the rotaion as well.
Thank You Again,
Winter Dragon
Yes, if you're referring to ActionScirpt, which is very similar to JavaScript, it can be done. Unforetunately, I don't have Flash... yet....
Winterdragon
03-24-2003, 08:42 PM
Jona,
You are referring to adding the ActionScript inside the Flash Animation right? If so, I never thought of doing it that way. The way I am understanding this is:
When the Intro plays, it checks the date, if date = 1,2, or 3 then use Graphic 1 in the bottom of the screen. if date = 4,5, or 6 then graphic 2 and so on.
Thats a very interesting take. I wasn't thinking outside of the box. I was thinking using JS in the Index page to tell it which Animation to load......
Thanks for the lightbulb :)
Winter Dragon