...

View Full Version : Is there any way to use a variable for SRC=



Ann-Marie
12-30-2011, 06:24 AM
I would like to have the page load a different images depending on SCRIPT variables.
Something like
<img src= pictures[n] etc.

Where pictures is something like
<SCRIPT language="JavaScript"
var pictures=[Smilyface.gif,Sadface.gif,mountain.jpg - - - etc];

xelawho
12-30-2011, 07:07 AM
randomly?


<html>
<head>
<script type="text/javascript">
var imgList = ['Smilyface.gif','Sadface.gif','mountain.jpg'];

window.onload = function() {
thepic=Math.floor(Math.random()*3)
document.getElementById('img').src =imgList[thepic];
}
</script>
</head>
<body>
<img id="img" src=''>
</body>
</html>

Philip M
12-30-2011, 07:21 AM
<script language=javascript> is long deprecated and obsolete. Use <script type = "text/javascript">.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum