/    Sign up×
Community /Pin to ProfileBookmark

Multiple Random Image Question

Hi. i am a beginner a javascript. i have a code that can have random images show up in 2 separate spots on a page. i want to change it to have random images load on 4 separate spots on a page, but i don’t know how. here is the code:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

<html xmlns=”http://www.w3.org/1999/xhtml“>

<head>
<meta http-equiv=”content-type” content=”text/html;charset=utf-8″ />
<meta name=”generator” content=”Adobe GoLive” />
<title>Test Page</title>
<link href=”../css/basic.css” rel=”stylesheet” type=”text/css” media=”all” />

<script language=”JavaScript”>

var theImages = new Array()
theImages[0] = ‘photo_00.jpg’
theImages[1] = ‘photo_01.jpg’
theImages[2] = ‘photo_02.jpg’
theImages[3] = ‘photo_03.jpg’
theImages[4] = ‘photo_04.jpg’

var otherImages = new Array()
otherImages[0] = ‘photo_05.jpg’
otherImages[1] = ‘photo_06.jpg’
otherImages[2] = ‘photo_07.jpg’
otherImages[3] = ‘photo_08.jpg’
otherImages[4] = ‘photo_09.jpg’

var j = 0
var p = theImages.length;
var preBuffer = new Array()
var preBuffer2 = new Array()
for (i = 0; i < p; i++){

preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
preBuffer2[i] = new Image()
preBuffer2[i].src = otherImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
var otherImage = Math.round(Math.random()*
(p-1));
function showImage(){
document.write(‘<img src=”‘+theImages[whichImage]+'”>’);
}
function showImage2(){
document.write(‘<img src=”‘+otherImages[otherImage]+'”>’);
}
</script>
</head>

<body leftmargin=”0″ marginheight=”0″ marginwidth=”0″ topmargin=”0″>
<table width=”800″ border=”0″ cellspacing=”0″ cellpadding=”0″ height=”180″>
<tr height=”180″>
<td width=”200″ height=”180″>
<script language=”JavaScript”>
showImage();
</script>
</td>
<td width=”200″ height=”180″>
<script language=”JavaScript”>
showImage2();
</script>
</td>
<td width=”200″ height=”180″>
<script language=”JavaScript”>
showImage3();
</script>
</td>
<td width=”200″ height=”180″>
<script language=”JavaScript”>
showImage4();
</script>
</td>
</tr>
</table>
</body>

</html>

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @mbockstruck 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.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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