I have a dropdown list that will show a corresponding layer according to which item in the list is selected.
My problem is, the external javascript file is shared among many pages. I need it to be more flexible than it currently is.
Right now it will only work for 3 items in a dropdown list and 3 corresponding layers. I need the script to work regardless of how many items are in the list.
Someone please help!
My Current script is below and HTML included.
Thanks guys,
TODD
<style type=”text/css”>
/*<![CDATA[
#e2, #e3 {
display: none;
}
/*]]>
</style>
<script type=”text/javascript”>
//<![CDATA[
function showElement(id)
{
if(!id) return;
for(i=1; i<=3; i++) document.getElementById(‘e’ + i).style.display = ‘none’;
document.getElementById(‘e’ + id).style.display = ‘block’;
}
//]]>
</script>
<form action=”#”>
<div>
<select onchange=”showElement(options[selectedIndex].value);”>
<option value=”1″>1</option>
<option value=”2″>2</option>
<option value=”3″>3</option>
</select>
</div>
</form>
<div id=”e1″>Layer 1</div>
<div id=”e2″>Layer 2</div>
<div id=”e3″>Layer 3</div>
[upl-file uuid=4431157f-b4e9-43c3-a890-a52b1fc51bb6 size=667B]hh.txt