473,404 Members | 2,187 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,404 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 985
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.