| re: Show/Hide Layers based on form option
veganeater wrote:[color=blue]
> Hi,
>
> I'm wondering if there's a way that I can select which <div> to show[/color]
based[color=blue]
> on the user's selection from a dropdown/listbox form.
>
> <form name="form1" method="post" action="">
> <select name="internet">
> <optgroup label="Network">
> <option label="option1">Internet</option>
> </optgroup>
> <optgroup label="Access">
> <option label="option2.0">Portal</option>
> <option label="option2.1">Webmail</option>
> <option label="option2.2">POP3 Email</option>
> <option label="option2.3">Messenger</option>
> <option label="option2.4">Newsgroups</option>
> </optgroup>
> </select>
> </form>
>
> Is there a way that I can have a particular <div> show based on a[/color]
selection[color=blue]
> from this list? I know that you can not directly apply actions to the
> options, so it presumably there has to be a javascript method of[/color]
doing it...[color=blue]
> If anyone can point me in the right direction, it would be greatly
> appreciated.
>
> Thanks in advance!
>
> |veganeater|
>
> // my apologies for the xpost on comp.lang.java.javascript[/color]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled</title>
<style type="text/css">
..showhide {
width: 130px;
height: 16px;
font-weight: 800;
text-align: center;
border: 2px black dashed;
display: none;
}
</style>
<script type="text/javascript">
var divs = {
'option1' : 'InternetDIV' ,
'option2.0' : 'PortalDIV' ,
'option2.1' : 'WebmailDIV' ,
'option2.2' : 'POP3DIV' ,
'option2.3' : 'MessengerDIV' ,
'option2.4' : 'NewsgroupsDIV'
}
function showhide(obj)
{
var el, v = obj.options[obj.selectedIndex].value;
for (var opt in divs)
if (el = document.getElementById(divs[opt]))
el.style.display = (opt != v) ? 'none' : 'block';
}
window.onload = function()
{
document.getElementById('internet').onchange();
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
<select id="internet" name="internet" onchange="showhide(this)">
<optgroup label="Network">
<option value="option1" selected="selected">Internet</option>
</optgroup>
<optgroup label="Access">
<option value="option2.0">Portal</option>
<option value="option2.1">Webmail</option>
<option value="option2.2">POP3 Email</option>
<option value="option2.3">Messenger</option>
<option value="option2.4">Newsgroups</option>
</optgroup>
</select>
</form>
<div id="InternetDIV" class="showhide">Internet</div>
<div id="PortalDIV" class="showhide">Portal</div>
<div id="WebmailDIV" class="showhide">Webmail</div>
<div id="POP3DIV" class="showhide">POP3 Email</div>
<div id="MessengerDIV" class="showhide">Messenger</div>
<div id="NewsgroupsDIV" class="showhide">Newsgroups</div>
</body>
</html> |