473,405 Members | 2,160 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,405 software developers and data experts.

Making window.document.images[] work in a loop

I am trying to have
"window.document.images[i].src=''+cards1[i]+'.gif'" work in a loop just
as "document.write(<img src="'+cards[i]+'">); does, but it does not
seem to be within Javascript's ability.

The following works:

for(var i=1;i<6;i++){

document.write('<td><img src="'+cards[i]+'.gif"></td>');

}

but this one does not:

for(var i=1;i<6;i++){

window.document.images[i].src=''+cards1[i]+'.gif";

}

Any help is greatly appreciated,
Thanks.

Jul 6 '06 #1
1 2504
Why would you want to do that. The document.images array is an array of
elements that are _already_ on the page.

If you which to pre-load graphics you can just create new image objects:

for (var i= 1 ; i < 6; i++) {
img = new Image();
img.src = cards1[i] + '.gif';
}

Or, you can put them in an array:

var cardImgs = new Array(6);
for (var i= 1 ; i < 6; i++) {
cardImgs[i] = new Image();
cardImgs[i].src = cards1[i] + '.gif';
}

Or you can add them to a page by using DOM (in the onload):

document.onload = function() {

for (var i= 1 ; i < 6; i++) {
var myImg = document.createElement('img');
myImg.src = cards1[i] + '.gif';
document.body.appendChild(myImg);
}
}

Good luck,
Vincent

ex********@yahoo.com wrote:
I am trying to have
"window.document.images[i].src=''+cards1[i]+'.gif'" work in a loop just
as "document.write(<img src="'+cards[i]+'">); does, but it does not
seem to be within Javascript's ability.

The following works:

for(var i=1;i<6;i++){

document.write('<td><img src="'+cards[i]+'.gif"></td>');

}

but this one does not:

for(var i=1;i<6;i++){

window.document.images[i].src=''+cards1[i]+'.gif";

}

Any help is greatly appreciated,
Thanks.
Jul 6 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: |-|erc | last post by:
Hi! Small challenge for you. The index.php uses this file and calls layout(). Take a look at www.chatty.net this file draws the chat login box on the right. I traced the CHAT button it submits...
4
by: Phillip Parr | last post by:
Hello, I have a nice system where someone clicks on a picture to show the full version. This pops up in a window.open box. It works great, the only problem is that if the user clicks a second...
1
by: Jiri Brada | last post by:
Hi, I have got a following problem with using Javascript: I have a HTML page with pictures' thumbnails. After clicking on any thumbnail, I would like to open a new window with the original...
2
by: Whitney | last post by:
I ran across a chunk of code that allows me to blend images in and out (works great!) but now I need to figure out a way to randomize the order that these images appear. I have a bunch of pics and...
14
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a...
4
by: shawn | last post by:
I have a simple script located here which loads different images when you click on some links. Everything works fine until you click on the last link which opens a popup window (zoom image). ...
9
by: tshad | last post by:
This was posted before but the message got messed up (all NLs were stripped out for some reason). I have 2 labels that hold the name of different images on my .aspx page. <asp:Label ID="Logo"...
1
by: soms2m | last post by:
HELLO ALL, I want to fill the parent window height with respect to the sub window height which is loading using ajax (mootools). For example if the parent window height is normal and the loading...
1
by: HACKhalo2 | last post by:
Hi. I'm helping a friend of mine develop an online game, which is currently outdated. The person making skins for the site came up with a cool looking NavBar (found at...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...
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,...

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.