Forum Moderators: open

Message Too Old, No Replies

use drop down selection image as link to different URL?

         

webtown06

10:12 pm on May 20, 2006 (gmt 0)

10+ Year Member



Hello JavaScript forum members:

I am doing a exercise for self study. the requirement is
a) when user choose a image names from drop down box, the image will shown, then choose another image name will replace previous image.

b) use selected image as links point to differnt URL, when On a MouseOver also have a Status Bar Message appear for each individual Image, on a MouseOut status image will be clared.

My first try is like this:

<body>

<h2 style = "text-align: center; color: #808080"> Choose a Picture and Jump</h2>

<center>
<form>
<select onChange="location.href=options[selectedIndex].value">
<option value="images/me.gif">Picture of me</option>
<option value="images/myaunt.gif">Picture of my aunt</option>
<option value="images/brother.gif">Picture of my brother</option>
</select>

</form>
</center>

</body>

Image get displayed, in the first try, but I don't know how to turn selected images as links.

hence I have my second thought <select onChange="showimage(this.form, this)">

this may need image swampping while user choose different images names in drop down box. Please give me
some advises on how to make this exercise work. I appreciate your help!

Jeff
5-20-06

MichaelBluejay

10:38 pm on May 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



My suggestion is to swap entire blocks of code, not just the image. Here's most of the code, not all of it. You'll need to add the code to the SELECT list that calls the function, and you'll need to add some code to the swap() function that hides the previous set of code.


<style type="text/css">.swappedIn { display:none} </style>

<script type="text/javascript">
swap(theDiv) {
document.getElementById('content').innerHTML = document.getElementById(theDiv).innerHTML;
document.getElementById(theDiv).style.display='block';
}
</script>

<select onchange="swap(...)"></select>

<div id=content></div>

<div id=one class=swappedIn>
<a href=/one.html><img src=one.jpg></a>
</div>

<div id=two class=swappedIn>
<a href=/two.html><img src=two.jpg></a>
</div>