473,236 Members | 1,627 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,236 software developers and data experts.

If then statement for graphic changes

2
I am wondering if it would be possible to set the display of a grahic on a website to change depending on the time of day it is. Say I want to have a night and day photgraph of a building on the website. Now can I have the page load with the proper picture relating to the time of day using if-then statements or would I need to try soemthing else if it is possible at all? Thank you!
Aug 11 '08 #1
4 982
RamananKalirajan
608 512MB
Ya surely you can do that with the help of the Date reference. I am just giving u the sample idea. In the window.onload have a function like this

[HTML]function checkDay()
{
var todate = new Date();
var hour = todate.getHours()
if(Hours<17) //upto Evening five
document.getElementById('picPosition').innerHTML = "Picture during Day Time";
else
document.getElementById('picPosition').innerHTML = "Picture during Night Time";

}[/HTML]
See this is a sample code, just try yours if any probs post back it. I will try to help u out

Regards
Ramanan Kalirajan
Aug 11 '08 #2
darmot
2
I guess I am more lost then i realized. I copied this and pasted it into my file yet nothing happened. I amde the changes I thought I needed to make such as the file names, and still nothing. Am I missing something? Perhaps this is more complex of an element then i was prepared for. If anyone has the time out there and can break it down to being very simple then maybe I can make it work on my site. Thank you very much for any efforts.
Aug 11 '08 #3
RamananKalirajan
608 512MB
Hi this is a working example instead of the div you replace it image tag and set the source in the condition part.

[HTML]<html>
<body onload="doThis()">
<div id="myDiv">
</div>
</body>
</html>
<script type="text/javascript">
function doThis()
{
var toDate = new Date();
var hours = toDate.getHours();
// alert(hours);
if(hours<18)
document.getElementById('myDiv').innerHTML="Beauti ful Day";
else
document.getElementById('myDiv').innerHTML="Beauti ful Evening Time";
}
</script>[/HTML]

Still any doubts post it back I will try to help u out.

Regards
Ramanan Kalirajan
Aug 12 '08 #4
acoder
16,027 Expert Mod 8TB
To set the source of the image, set its src property, e.g.
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("myImg").src = "daytime.png";
You could also set this using server-side code, but then that would be based on server-time rather than the client.
Aug 12 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: entoone | last post by:
print "\t\t<td><bgcolor=#000000><font color=#000000 font color=#000000 face=Tahoma size=2 ><A href='show.php?searchid=$line'>More Info</td>\n"; How would I subsittue text for a graphic in php,...
1
by: Jamie Meredith | last post by:
We are a small graphic design firm who is fighting a growth spurt which has resulted in an overload in our handling of email and proofing. We are looking for a pre-built, open source PHP/MYSQL...
3
by: Racket | last post by:
Buttons down the left A, B, C, D A graphic to the right. As you hover over A or B etc the graphic on the right changes. It's a common one. Need a script to do this, with or without...
5
by: Charax | last post by:
Is it possible to use CSS to define <hr> as a graphic image? FrontPage 2003 has apparently dropped the graphic hr from their themes and I am becoming more involved in using CSS, but would like to...
0
by: Brett | last post by:
I have a program that prints 2 different reports and I have 2 different printers (hp 9000, hp9050). The first report prints perfectly on both printers. The second only prints pefectly on the...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
0
by: Thag | last post by:
Hi! I am currently trying to get an overview about the possibility of separating graphical data from its animations. More specifically speaking, the graphical data is made up from 3D-CAD...
6
by: randy1200 | last post by:
I'm using Visual Studio 2005 and C#. I need to print a WinForm used for data entry as a graphic. In other words, I need to print the exact WinForm the user sees on the screen. I searched through...
1
by: Rabel | last post by:
I want to use a graphic to do a function I already have done but I want the graphic to change to another graphic, after it is clicked, and do a different function that I have finished when it...
1
by: icepick72 | last post by:
On an academic note, I want to copy a Graphic to an Image (Bitmap). I have the Graphic object but not the origin image from which it originates; this is because I'm overriding the PrintDocument...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.