Forum Moderators: open
I have a javascript function which basically toggles the visibility of layers.... no bother there!
Ok, now I have a dropdown list, and what I would like to do is use the onChange method in the <select> tag to somehow run this function... doing onChange="showLayer(layername)" is no bother, however, where I am having a problem is that I want to populate the layerName with the selected value of the dropdown box, eg:
<select name="selectme" onChange="showLayer(this.selected)
{or onChange="showLayer(document.form.selectme.value)"}"
<option value="layer1name">1</option>
<option value="layer2name">2</option>
<option value="layer3name">3</option>
</select>
Thanks in advance for any suggestions or tips,
Alex
<select name="selectme" onChange="showLayer(this)">
<option value="layer1name">1</option>
<option value="layer2name">2</option>
<option value="layer3name">3</option>
and then in showLayer
showLayer(x)
{
makevisible(x.options(x.selectedIndex).text)
}
Typically, having just posted the topic I solved the puzzle!
OK, the swapLayer() finction is contained in an external JS file (where the following code is about to be moved to also!).
<script language="JavaScript">
function showListLayer()
{
showLayer(document.primarylist.mlist.options[document.primarylist.mlist.selectedIndex].value);
}
</script>
Then:
<form name="primarylist">
<select name="mlist" onChange="showListLayer()">
<added>
In fact, you can do away with the extra JavaScript function totally and just use:
<select name="mlist" onChange="showLayer(this.options[this.selectedIndex].value);">
Much neater by far!
</added>