/    Sign up×
Community /Pin to ProfileBookmark

Images in an array

Hi,
I have a page that displays images that are taken out of an array in an external file. There are about five images in the array. I wrote the file a long time ago and in HTML and I am now trying to validate it in XHTML.

parts of my javascript code

//Display images

var images = image[index+1];

document.getElementById(“mypage”).img.src = images;

}

When I changed the form from
<image name=”img” src=””/> to

<input type=”image” name=”img” src=””/> the images no longer display and there is a javascript error.

Is there an easy way of fixing the problem?

Thanks.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@FangSep 15.2007 — Could you post a link or more of the code. None of the code given would work.
Copy linkTweet thisAlerts:
@hoangkcSep 15.2007 — javascript:

var images = image[index+1];

document.getElementById("img").src = images;

HTML:

<img id="img" src=""/>
Copy linkTweet thisAlerts:
@ApekatthjerneSep 16.2007 — What is the variable index? The problem with your script is that it requires an img tag on the page, which to begin with, doesn't have a src attribute (nor width or height) - thus, not validating.

If you want to preload images so that you can just inject the image url and have it appear instantly instead of it having to load, then use this script:
[CODE]
var a = ['http://www.example.com/image001.jpg', 'http://www.example.com/image002.gif', 'http://www.example.com/image003.gif']; // the array of image urls.
var b = []; // just a temporary arrray.

for(var i = 0, aLength = a.length; i < aLength; i++)
{
+
b[i] = new Image;
b[i].src = a[i];
}
[/CODE]
×

Success!

Help @Sarah22 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...