943,778 Members | Top Members by Rank

Ad:
Apr 12th, 2008
0

Using an array in Javascript

Expand Post »
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>
Gia
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Gia is offline Offline
8 posts
since Nov 2007
Apr 13th, 2008
0

Re: Using an array in Javascript

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. ...
Reputation Points: 10
Solved Threads: 4
Newbie Poster
HenryGR is offline Offline
24 posts
since Mar 2008
Apr 13th, 2008
0

Re: Using an array in Javascript

Thanks! I'll try that.
Gia
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Gia is offline Offline
8 posts
since Nov 2007
Apr 15th, 2008
0

Re: Using an array in Javascript

> images[0] = new image();

images[0] = new Image();
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Apr 15th, 2008
0

Re: Using an array in Javascript

Oops!
Sorry for the typo.
Thank YOU ~s.o.s~
Reputation Points: 10
Solved Threads: 4
Newbie Poster
HenryGR is offline Offline
24 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: How do I identify what type and where my code is in the HTML DOM tree?
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: AJAX DIV Refresh Help....





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC