showing and hiding something based on selection made

M

middletree

I had this going yesterday, but it seems to be forgotten because it's
so far down the list now.

www.middletree.net/dropdown.htm This is from an Intranet app I have
going in ASP. I have no actual URL to show you, but this should work.

Find the <select> dropdown called Type of Ticket. Now find the one
called Environment. The boss wants a couple of things to be hidden from
the user unless both of the following two conditions are met:

1. "Problem" is selected on Type of Ticket.
2. "Production" is selected on Environment.

The part of the page that you'll want to key in on is the function
called displayRadios.

In the case of the page I am posting, please note that it's a page for
editing an existing ticket, so it happens to have Production and
Problem pre-selected. On other versions of this same page, other things
might be pre-selected.

Anyway, when this page, loads, it doesn't show the parts that I am
hoping will show. No JS error is present on load. However, when you try
and change either of the dropdowns, the JS function is fired off, and
that throws the error.

Any help appreciated.
 
F

FunGuySF

Not sure I fully understand, but this should be close:

I'm not sure what you want to show or hide from the user. I'll assume it's
in a <div id="secretstuff"> or <span id="secretstuff">

something like this maybe?

<html>
<head>
<title>Show/Hide Demo</title>
<script type="text/javascript">
function showhide() {
var typeofticket =
document.getElementById("typeofticket").selectedIndex;
var environment =
document.getElementById("environment").selectedIndex;
if (typeofticket == 1 && environment == 1) {
document.getElementById("secretstuff").style.display = "inline";
} else {
document.getElementById("secretstuff").style.display = "none";
}
}
</script>
</head>
<body>
<form>
<p><select size="1" name="typeofticket" onchange="showhide();">
<option>Choice 1</option>
<option>Problem</option>
</select><select size="1" name="environment" onchange="showhide();">
<option>Choice 1</option>
<option>Production</option>
</select></p>
</form>
<div id="secretstuff" style="display:none">Secret Stuff is here!</div>
</body>
</html>
 
R

RobG

FunGuySF wrote:
[...]
document.getElementById("secretstuff").style.display = "inline";

Better to use:

...display = "";

then the default will be used (inline, block, whatever) and you don't
accidentally set it to the wrong one.

Please don't top-post and remove any unnecessary quoted text from the
reply (see the group FAQ at:

<URL:http://www.jibbering.com/faq/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top