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

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];

12-30-2011, 07:07 AM

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

window.onload = function() {
document.getElementById('img').src =imgList[thepic];
<img id="img" src=''>

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