Hi
I am trying to create some websites in that website i have images field in that image field(totally i have 12 images) in my website i want to update my images according to month.If the month is january i want to display first picture .if it is feb then it shows 2nd image like this.I created like for a week but i cant find idea for this can anyone help me and can anyone send some example code for this.
thanks
11 2935
Hi
I am trying to create some websites in that website i have images field in that image field(totally i have 12 images) in my website i want to update my images according to month.If the month is january i want to display first picture .if it is feb then it shows 2nd image like this.I created like for a week but i cant find idea for this can anyone help me and can anyone send some example code for this.
thanks
rename your images to img0.gif, img1.gif, .... img11.gif; -
<img src="" id="monthImage">
-
<script language=javascript type="text/javascript">
-
document.getElementById("monthImage").src = "abc/img" + new Date().getMonth() + ".gif";
-
</script>
gits 5,390
Recognized Expert Moderator Expert
hi ...
you may use an js-object, and the date-object like the following: -
// create actual date
-
var date = new Date;
-
-
// img-list ... example
-
var cal_images = {
-
0: 'default.jpg',
-
1: 'imgsrc1.jpg',
-
2: 'imgsrc2.jpg',
-
3: 'imgsrc3.jpg'
-
};
-
-
// you need a reference to the image-node ... then set the src
-
// according to date's month
-
var month = date.getMonth() + 1;
-
img_ref.src = typeof cal_images[month] != 'undefined' ?
-
cal_images[month] : cal_images[0] ;
-
kind regards
hi ...
you may use an js-object, and the date-object like the following: -
// create actual date
-
var date = new Date;
-
-
// img-list ... example
-
var cal_images = {
-
0: 'default.jpg',
-
1: 'imgsrc1.jpg',
-
2: 'imgsrc2.jpg',
-
3: 'imgsrc3.jpg'
-
};
-
-
// you need a reference to the image-node ... then set the src
-
// according to date's month
-
var month = date.getMonth() + 1;
-
img_ref.src = typeof cal_images[month] != 'undefined' ?
-
cal_images[month] : cal_images[0] ;
-
kind regards
Yea, your solution is better gits.
Hi,
Sorry you gave some solution i tried with that but it shows error
in here -
img_ref.src = typeof cal_images[month] != 'undefined' ?
-
cal_images[month] : cal_images[0] ;
-
img_ref.src is undefined can u tell me what is that img_ref.src
Yea, your solution is better gits.
gits 5,390
Recognized Expert Moderator Expert
img_ref has to be a reference to your image-node in the document ... example as follows:
in you html you must have - note the id-attribute there:
[HTML]<img src="imgsrc.jpg " alt="some_alt_d escr" id="whatever_im g_id"/>[/HTML]
now you may get a reference to the node with: - var img_ref = document.getElementById('whatever_img_id');
and this img_ref must be the img_ref in our example above where you get an error. because img_ref has to be declared and assigned the way i showed you here ...
kind regards
I still don't get it. If i put
<img src="imgsrc.jpg " alt="some_alt_d escr" id="whatever_im g_id"/>
in an html page isn't it going to only load "imgsrc.jpg " ?
acoder 16,027
Recognized Expert Moderator MVP
I still don't get it. If i put
<img src="imgsrc.jpg " alt="some_alt_d escr" id="whatever_im g_id"/>
in an html page isn't it going to only load "imgsrc.jpg " ?
You should use this in addition to the other code. It will load imgsrc.jpg, but the Javascript code will change the src of the image automatically.
Thanks for the reply.
I'm sorry but I'm still not getting it- JS isn't my strong suite, and I have to do a monthly calander thing for work...otherwis e i'd screw with it till i figured it out...
Does the
var img_ref = document.getEle mentById('whate ver_img_id');
line go into the large script above? if so does it have to be placed specifically?
Thanks & Regards
gits 5,390
Recognized Expert Moderator Expert
hi ...
have a look at the following combined code: -
// create actual date
-
var date = new Date;
-
-
// img-list ... example
-
var cal_images = {
-
0: 'default.jpg',
-
1: 'imgsrc1.jpg',
-
2: 'imgsrc2.jpg',
-
3: 'imgsrc3.jpg'
-
};
-
-
// you need a reference to the image-node ... then set the src
-
// according to date's month
-
-
// this gets the reference to the image with id named 'whatever_img_id'
-
var img_ref = document.getElementById('whatever_img_id');
-
-
var month = date.getMonth() + 1;
-
img_ref.src = typeof cal_images[month] != 'undefined' ?
-
cal_images[month] : cal_images[0] ;
-
kind regards
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Hennie de Nooijer |
last post by:
Hi,
Currently we're a building a metadatadriven datawarehouse in SQL
Server 2000. We're investigating the possibility of the updating
tables with enormeous number of updates and insert and the use of
checkpoints (for simple recovery and Backup Log for full recovery).
On several website people speak about full transaction log and the
pace...
|
by: Hasanain F. Esmail |
last post by:
Hi all,
I sincerly thank you all in advance for your help to solve this
problem.
I have been trying to find a solution to this problem for sometime now
but have failed.
I am working on a project that requires updating data every month.
A typical examle is an apartment rental software but could be applied
|
by: Tc |
last post by:
Hi,
I was curious, I am thinking of writing an application that loads a dataset
from a database that resides on a server. The question I have is this, if
multiple copies of the app will be running at once will there be problems
with data updates?
The reason I ask is I'm thinking like this:
User1 launches the app and the dataset is...
|
by: ameyas |
last post by:
hi all,
i am using an image which has image map and i provide the href action
url. i have provided the url to open a pop up window like
"javascript:window.open('www.google.com');" but on clicking the image,
the page (main window) gets refreshed in the background the pop up
opens as desired.
is there a way to cancel the refreshing of...
|
by: Jerry West |
last post by:
I have a routine that updates a PictureBox image every x seconds. I do this
by first loading an array with the path to all of the images. I then
generate a random number to use as the index of the array. A timer is set to
update the PictureBox. This works great the first time through but fails on
all subsequent Timer events. If I simply step...
| |
by: EyeHawk |
last post by:
OK, hopefully somebody can help me out again.
My next problem is updating 3 form fields (type list/menu option) that correspond to a date, one for month, one for day and one for year when the user selects a date for a javascript calendar solution.
Introduction
The reason I don’t want to use a text field, is because the website I’m developing...
|
by: Eminosoft |
last post by:
The below code can't take the images.plz tell that what is the problem in that code
<?php
// Connect to database
$errmsg = "";
if (! @mysql_connect("localhost","root","sreeni")) {
$errmsg = "Cannot connect to database";
}
|
by: sravani1 |
last post by:
This code runs like when i submit the form it takes the image and displayed and top of the image a map will displayed. But actually i want that when i give the image it checks the location in the map and after displayed it.plz tell that how to start the logic.
<?php
// Connect to database
$errmsg = "";if (!...
|
by: Stevo |
last post by:
I'm guessing this is a laughably obvious answer to many here, but it's
not to me (and I don't have a server or any knowledge of PHP to be able
to try it). It's not strictly a PHP question, but something that PHP
guys would know the answer to. I can't think of a more appropriate forum
to try. I've heard the ASP and JSP guys aren't as friendly...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |