VisionsIC
09-23-2004, 06:47 PM
Grettings To All,
This is my first post on here. I am new to Javascript but find it very exciting. I am trying to work with the Date Object to load a particular image according to the current date on the system clock(client-side). My first experiment was successful. With the code shown below, I was able to get an image I specifically named "dg0.jpg" to load to the webpage using the date object. I named these .jpg files as such:
example - 1
-----------------------------------------------------------------------
dg0.jpg
dg1.jpg
dg2.jpg, and so forth.
-----------------------------------------------------------------------
Here is the working code:
-----------------------------------------------------------------------
<script language="Javascript">
document.write('<IMG SRC="dg0.jpg" name="tip" BORDER=0>');
today=new Date();
dateno=today.getDate();
if (document.images)
{document.tip.src="dg"+dateno+".jpg";}
</script>
-----------------------------------------------------------------------
That codes allows to place an image to the webpage based on the current day of the month. Now, I attempted to further experiment by trying to get similar results by not only the days in the month, but also the months too. I figured if Javascript determines the right thing to do with the name of the image file hypothetically like this:
example - 2
-----------------------------------------------------------------------
dg0.jpg ("dg" + "0" + ".jpg")
"dg" (prefix name)
"0" (number used by the date object to determine the proper image to pull according to the current day)
".jpg" (to place the correct image type)
-----------------------------------------------------------------------
If this is true, I tried the same approach with adding the month:
example - 3
-----------------------------------------------------------------------
dg0_8.jpg ("dg" + "0" + "_" + "8" + ".jpg")
"dg" (prefix name)
"0" (number used by the date object to determine the proper image to pull according to the current day)
"_" (an underscore used as a seperator name)
"8" (number used by the date object to determine the proper image to pull according to the current month)
".jpg" (to place the correct image type)
-----------------------------------------------------------------------
Here is the incorrect code I wrote for the above "example - 3".
-----------------------------------------------------------------------
<script language="Javascript">
document.write('<IMG SRC="dg0_8.jpg" name="tip" name="gap" BORDER=0>');
today=new Date();
dateno=today.getDate();
monthno=getMonth();
if (document.images)
{document.tip.src="dg"+dateno+.gap.src="_"+monthno+".jpg";}
</script>
-----------------------------------------------------------------------
Can this be corrected to function properly? I am very open for suggestions...
Aaron (VisionsIC)
This is my first post on here. I am new to Javascript but find it very exciting. I am trying to work with the Date Object to load a particular image according to the current date on the system clock(client-side). My first experiment was successful. With the code shown below, I was able to get an image I specifically named "dg0.jpg" to load to the webpage using the date object. I named these .jpg files as such:
example - 1
-----------------------------------------------------------------------
dg0.jpg
dg1.jpg
dg2.jpg, and so forth.
-----------------------------------------------------------------------
Here is the working code:
-----------------------------------------------------------------------
<script language="Javascript">
document.write('<IMG SRC="dg0.jpg" name="tip" BORDER=0>');
today=new Date();
dateno=today.getDate();
if (document.images)
{document.tip.src="dg"+dateno+".jpg";}
</script>
-----------------------------------------------------------------------
That codes allows to place an image to the webpage based on the current day of the month. Now, I attempted to further experiment by trying to get similar results by not only the days in the month, but also the months too. I figured if Javascript determines the right thing to do with the name of the image file hypothetically like this:
example - 2
-----------------------------------------------------------------------
dg0.jpg ("dg" + "0" + ".jpg")
"dg" (prefix name)
"0" (number used by the date object to determine the proper image to pull according to the current day)
".jpg" (to place the correct image type)
-----------------------------------------------------------------------
If this is true, I tried the same approach with adding the month:
example - 3
-----------------------------------------------------------------------
dg0_8.jpg ("dg" + "0" + "_" + "8" + ".jpg")
"dg" (prefix name)
"0" (number used by the date object to determine the proper image to pull according to the current day)
"_" (an underscore used as a seperator name)
"8" (number used by the date object to determine the proper image to pull according to the current month)
".jpg" (to place the correct image type)
-----------------------------------------------------------------------
Here is the incorrect code I wrote for the above "example - 3".
-----------------------------------------------------------------------
<script language="Javascript">
document.write('<IMG SRC="dg0_8.jpg" name="tip" name="gap" BORDER=0>');
today=new Date();
dateno=today.getDate();
monthno=getMonth();
if (document.images)
{document.tip.src="dg"+dateno+.gap.src="_"+monthno+".jpg";}
</script>
-----------------------------------------------------------------------
Can this be corrected to function properly? I am very open for suggestions...
Aaron (VisionsIC)