473,583 Members | 4,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating image every month automatically in js

23 New Member
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
Jul 26 '07 #1
11 2935
sumittyagi
202 Recognized Expert New Member
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;
Expand|Select|Wrap|Line Numbers
  1. <img src="" id="monthImage">
  2. <script language=javascript type="text/javascript">
  3. document.getElementById("monthImage").src = "abc/img" + new Date().getMonth() + ".gif";
  4. </script>
Jul 26 '07 #2
gits
5,390 Recognized Expert Moderator Expert
hi ...

you may use an js-object, and the date-object like the following:

Expand|Select|Wrap|Line Numbers
  1. // create actual date
  2. var date = new Date;
  3.  
  4. // img-list ... example
  5. var cal_images = {
  6.     0: 'default.jpg',
  7.     1: 'imgsrc1.jpg',
  8.     2: 'imgsrc2.jpg',
  9.     3: 'imgsrc3.jpg'
  10. };
  11.  
  12. // you need a reference to the image-node ... then set the src
  13. // according to date's month
  14. var month   = date.getMonth() + 1;
  15. img_ref.src = typeof cal_images[month] != 'undefined' ? 
  16.         cal_images[month] : cal_images[0] ;
  17.  
kind regards
Jul 26 '07 #3
sumittyagi
202 Recognized Expert New Member
hi ...

you may use an js-object, and the date-object like the following:

Expand|Select|Wrap|Line Numbers
  1. // create actual date
  2. var date = new Date;
  3.  
  4. // img-list ... example
  5. var cal_images = {
  6.     0: 'default.jpg',
  7.     1: 'imgsrc1.jpg',
  8.     2: 'imgsrc2.jpg',
  9.     3: 'imgsrc3.jpg'
  10. };
  11.  
  12. // you need a reference to the image-node ... then set the src
  13. // according to date's month
  14. var month   = date.getMonth() + 1;
  15. img_ref.src = typeof cal_images[month] != 'undefined' ? 
  16.         cal_images[month] : cal_images[0] ;
  17.  
kind regards
Yea, your solution is better gits.
Jul 26 '07 #4
kavithadevan
23 New Member
Hi,
Sorry you gave some solution i tried with that but it shows error

in here

Expand|Select|Wrap|Line Numbers
  1. img_ref.src = typeof cal_images[month] != 'undefined' ? 
  2.         cal_images[month] : cal_images[0] ;
  3.  
img_ref.src is undefined can u tell me what is that img_ref.src

Yea, your solution is better gits.
Jul 26 '07 #5
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:

Expand|Select|Wrap|Line Numbers
  1. 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
Jul 26 '07 #6
childoflusankya
3 New Member
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 " ?
Aug 1 '07 #7
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.
Aug 1 '07 #8
childoflusankya
3 New Member
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
Aug 1 '07 #9
gits
5,390 Recognized Expert Moderator Expert
hi ...

have a look at the following combined code:

Expand|Select|Wrap|Line Numbers
  1. // create actual date
  2. var date = new Date;
  3.  
  4. // img-list ... example
  5. var cal_images = {
  6.     0: 'default.jpg',
  7.     1: 'imgsrc1.jpg',
  8.     2: 'imgsrc2.jpg',
  9.     3: 'imgsrc3.jpg'
  10. };
  11.  
  12. // you need a reference to the image-node ... then set the src
  13. // according to date's month 
  14.  
  15. // this gets the reference to the image with id named 'whatever_img_id'
  16. var img_ref = document.getElementById('whatever_img_id');
  17.  
  18. var month   = date.getMonth() + 1;
  19. img_ref.src = typeof cal_images[month] != 'undefined' ? 
  20.         cal_images[month] : cal_images[0] ;
  21.  
kind regards
Aug 2 '07 #10

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

Similar topics

6
5759
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...
6
2989
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
3
13026
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...
4
5156
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...
4
13432
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...
1
2041
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...
3
2082
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"; }
1
2012
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 (!...
16
2971
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...
0
7825
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...
0
8323
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7933
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...
0
8191
tracyyun
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...
1
5700
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5372
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...
0
3816
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...
1
1431
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1155
bsmnconsultancy
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...

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.