Search code examples
javascripthtmlimagepreview

Preview Image with Values from Select with Javascript


in my script, I have a select-field:

<select name="src[jumpMenu]" id="jumpMenu" onchange="ChangeImage(this.value,'preview');">
    <option value="A">AStyle</option>
    <option value="B">BStyle</option>
    <option value="C">CStyle</option>
</select>

and I got this Javascript below:

<script language="Javascript" type="text/javascript">
<!--
function ChangeImage(newimage,imageid) {
if(document.getElementById(imageid).src != newimage)
   document.getElementById(imageid).src = newimage;
}
// -->
</script>

and here is my problem:

I can't change the values because of the dependence for the other files (which I won't change).

Do you know any solution how to switch "A" to "img/src/A_top.png" for example and get it working with this script?

Thanks.


Solution

  • document.getElementById(imageid).src = "img/src/"+newimage+"_top.png";