Select List Alters Images

[Total: 0    Average: 0/5]

This allows one to select an item in a select list and have an image change accordingly.

Body Code:

<img src="/js/pic3.gif" width="25" height="25" border="0" name="flyer"> 


with a form like this 
<script>
var _img = new Array();
    _img[0] = new Image(); _img[0].src="/js/pic1.gif";
    _img[1] = new Image(); _img[1].src="/js/pic2.gif";
    _img[2] = new Image(); _img[2].src="/js/pic3.gif";
    _img[3] = new Image(); _img[3].src="/js/pic4.gif";
function doIt(_obj)
{
  if(!_obj)return;
  var _index = _obj.selectedIndex;
  if(!_index)return;
  var _item  = _obj[_index].value;
  if(!_item)return;
  if(_item<0 || _item >=_img.length)return;
  document.images["flyer"].src=_img[_item].src;
}
</script>
<form method="get"> 
<select onchange="doIt(this)">
<option value="">Select a Picture</option> 
<option value="0">pic 1</option> 
<option value="1">pic 2</option> 
<option value="2">pic 3</option> 
<option value="3">pic 4</option> 
</select> 
</form> 

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *