How to select an element by id and swapping an image ?

Bharathi Cherukuri
Posted by Bharathi Cherukuri under JavaScript category on | Points: 40 | Views : 1565
Here is an example to select an element by id and swapping an image.

<script language="JavaScript" type="text/javascript" >
function setBabyIcon() {

var babyIcon = document.getElementById("babyIcon");
babyIcon .src = "images/"+getSelectValue("baby")+".jpg";


<img border="0" src="" id="typeIcon" alt="type" />

<select name="baby" id="baby" onChange="setButton();setBabyIcon();">
<option value="--Select--">Select baby</option>
<option value="Baby1">Baby1</option>
<option value="Baby2">Baby2</option>
<option value="Baby3">Baby3</option>
<option value="Baby4">Baby4</option>
<option value="Baby5">Baby5</option>
<option value=""></option>

Comments or Responses

Login to post response