Forum : How to select an element by id and swapping an image?
Brief description  about Online courses   join in Online courses
View prabeen  patra 's Profile

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

Hi sir,

How to select an element by id and swapping an image?
Asked by prabeen patra | Nov 27, 2009 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
Hi Prabeen,

Go through the code given below:

<script language="JavaScript" type="text/javascript" >
function setBeerIcon() {
var beerIcon = document.getElementById("beerIcon");
beerIcon.src = "images/"+getSelectValue("beer")+".jpg";
}
</script>

<img border="0" src="" id="brandIcon" alt="brand" />

<select name="beer" id="beer" onChange="setButton();setBeerIcon();">
<option value="--Select--">Select beer</option>
<option value="heineken">heineken</option>
<option value="sol">sol</option>
<option value="amstellight">amstellight</option>
<option value="coronalight">coronalight</option>
<option value="coronaextra">coronaextra</option>
<option value=""></option>
</select>

Nov 27, 2009