Using an array in Javascript

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Nov 2007
Posts: 8
Reputation: Gia is an unknown quantity at this point 
Solved Threads: 0
Gia's Avatar
Gia Gia is offline Offline
Newbie Poster

Using an array in Javascript

 
0
  #1
Apr 12th, 2008
Hi. I need some help with arrays in JavaScript. I am creating a slideshow and have to store the images in an array on a separate file. I need some feedback as far as am I missing something in this file and how can I then call this array into my slideshow file? So far, I have:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2.  
  3. // Create an array to hold image filenames
  4. var images = new Array();
  5.  
  6. // Populate array with image filenames
  7. imgname[0] = 'home.jpg';
  8. imgname[1] = 'beach.jpg';
  9. imgname[2] = 'pool.jpg';
  10. imgname[3] = 'garden.jpg';
  11. imgname[4] = 'pond.jpg';
  12. imgname[5] = 'car.jpg';
  13.  
  14. </script>
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 22
Reputation: HenryGR is an unknown quantity at this point 
Solved Threads: 3
HenryGR's Avatar
HenryGR HenryGR is offline Offline
Newbie Poster

Re: Using an array in Javascript

 
0
  #2
Apr 13th, 2008
You create a new array
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var images = new Array();

and then you want to reference
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. imgname[0] = 'home.jpg';
  2. ...

..hmmm! names do not match.

Also, creating a new array, does not create a new array if images... you may want to create the elements of the array as:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. images[0] = new image();
  2. image[0].src = 'home.jpg';
  3.  
  4. ...
You keep going, have a Nice day!
Henry.

Before printing this message, make sure is necessary.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 8
Reputation: Gia is an unknown quantity at this point 
Solved Threads: 0
Gia's Avatar
Gia Gia is offline Offline
Newbie Poster

Re: Using an array in Javascript

 
0
  #3
Apr 13th, 2008
Thanks! I'll try that.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,609
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 464
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Using an array in Javascript

 
0
  #4
Apr 15th, 2008
> images[0] = new image();

images[0] = new Image();
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 22
Reputation: HenryGR is an unknown quantity at this point 
Solved Threads: 3
HenryGR's Avatar
HenryGR HenryGR is offline Offline
Newbie Poster

Re: Using an array in Javascript

 
0
  #5
Apr 15th, 2008
Oops!
Sorry for the typo.
Thank YOU ~s.o.s~
You keep going, have a Nice day!
Henry.

Before printing this message, make sure is necessary.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC