PDA

View Full Version : Toggle Links Behind an Image Tag Upon User Selection From a Dropdown Menu



jiapei_jen
Apr 9th, 2007, 08:38 PM
I would like to create a dropdown menu in the first <td> cell. Then, I would like the <a href="....."></a> to toggle to different links behind an image that I put in the second <td> cell.

I could only manage to toggle the links when a selection from the dropdown menu is made. I am unable to establish the relation between menu selection and the <a href="...."></a>

Really need help. Thank you.



<script type="text/javascript">
function toggleLookup(menuSelection)
{
if (document.searchCommodityRequests.dutyStation.value != "null")
{
document.location.href = menuSelection }
}
</script>

.....

<td>
<select name="dutyStation" onChange="toggleLookup(document.searchCommodityRequests.dutyStation.options[document.searchCommodityRequests.dutyStation.options.selectedIndex].value)">
<option>Select</option>
<option value='Delete_a_Row.html'>Organization</option>
<option value='deleteRowsExample.html'>Location</option>
</select>
</td>
<td>
<a href="">
<img src="../images/viewList.gif" alt="view code list" border="0/>
</a>
</td>

.....

rwedge
Apr 10th, 2007, 08:10 AM
You must reference the link:
<script type="text/javascript">
function toggleLookup(menuSelection) {
if (menuSelection) {
document.getElementById('tlk').href = menuSelection ;
}
}
</script>


<form name="searchCommodityRequests" id="searchCommodityRequests" method="post" action="" enctype="multipart/form-data">
<select name="dutyStation" onChange="toggleLookup(document.searchCommodityRequests.dutyStation.options[document.searchCommodityRequests.dutyStation.options.selectedIndex].value)">
<option>Select</option>
<option value='Delete_a_Row.html'>Organization</option>
<option value='deleteRowsExample.html'>Location</option>
</select>
</form>

<a id="tlk" href=""><img src="../images/viewList.gif" alt="view code list" border="0" /></a>

jiapei_jen
Apr 10th, 2007, 01:35 PM
Thanks very much for your reply and help.

The code works exactly as I would like to accomplish. Your guidance makes sense. I should learn some more about JavaScript coding instead of looking for code on the internet.