/    Sign up×
Community /Pin to ProfileBookmark

image gallery help

Hi i am new to ‘javascript and am trying to construct an image gallery using javascript and the document.getelementbyidproperty… I have 2 questions !

here is my code at the moment.. working.

<html>
<head>
<script type=”text/javascript”>

myImages=new Array()

myImages[0]=”images/1.jpg”
myImages[1]=”images/2.jpg”
myImages[2]=”images/3.jpg”

imagecounter=myImages.length-1
i=0

function first()
{
document.getElementById(‘imageviewer’).src=myImages[0],
i=0

}
function second()
{
document.getElementById(‘imageviewer’).src=myImages[1]
i=1
}
function third()
{
document.getElementById(‘imageviewer’).src=myImages[2]
i=2
}
</script>
</head>

<body>
<center>
<form>

<img src=”images/1.jpg” width=50 height=50 onclick=”first()” >
<img src=”images/2.jpg” width=50 height=50 onclick=”second()”>
<img src=”images/3.jpg” width=50 height=50 onclick=”third()”>
</form>
<img id=”imageviewer” src=”blank.jpg” alt=”Click on an image to view details” width=”200″ height=”200″ />
</center>
</body>
</html>

QUESTION 1
Is there any way to create a loop for the functions i have created. i.e. if i have 3 images i need 3 functions, if i had 10 images i need 10 functions. Using a loop of some sort is it possible to create 1 function regardless of how many images i have.

QUESTION 2
I would like to have information about the image come up next to it… what would be the best way to implement this……

Thanx in advance for any help……..

Cheers.. ev

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@evan83authorMay 16.2005 — Dont Worry Found My Solution!!

Cheers! Wohooooooooooo
×

Success!

Help @evan83 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 5.3,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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