The situation: I created an image gallery. Thumbnails are showed and onmouseover, the certain image is displayed in another container in big. Each image has an description, which can be retrieved by the simple function. When an image is hovered (onmouseover) I would like to set the specific image and get its description.
The problem: The onmouseover-event calls the function "hover()". Within this function, the source for the big image is changed to the selected one. I cannot get it to work to change the value for the description div container. By now, I simply tried to change the text to anything, in the end, the real description value which is stored in the "getDescription()" function should be received.
What I tried: I tried different versions and combinations to access the text of the description div container. Using "document.getElementById('description').innerHTML="+i+" changes the value, but it sets the value fixed for the last/highest i.
The code:
<div id="thumbnails">
</div><br/>
<div id="description" style="width:100%; text-align:center;"> text </div>
<div class="preview" align="center">
<img id="preview" name="preview" src="images/img1.jpg"/>
</div>
<script type="text/javascript">
for (var i=1; i<=5; i++) {
document.getElementById("thumbnails").innerHTML += "<img onmouseover="+hover(i)+" name='img"+i+"' src='images/img"+i+".jpg'/>";
}
function hover(i) {
return "'preview.src=img"+i+".src'"; //works, but does not include the change of the description
return "'preview.src=img"+i+".src'; 'description.innerHTML="+i+"'"; //does not work
}
function getDescription(value)
{
return value == '1' ? "description 1":
value == '2' ? "description 2":
value == '3' ? "description 3":
value == '4' ? "description 4":
value == '5' ? "description 5": '';
}
</script>
Note: Any help is appreciated, but I cannot use jquery.