mrslate1
asked on
Show/Hide image or content based on form drop down choice
I have the need to create a small form with a select box with three choices. Choice 1, choice 2 choice3.
Choice 1 shows content in a specified area and hides choice 2,3 , Choice 2 Hides Choice 1 and 3 and shows choice 2, Choice 3 shows Choice three content and hides choice 1 and 2.
Hope this makes sense. I have come close but my content keeps overlapping when the choices are changing.
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form name="form1" method="post" action="">
<div id="Layer1" style="position:absolute; left:200px; top:150px; width:455px; height:131px; z-index:1; visibility: hidden">
Content 1 </div>
<div id="Layer2" style="position:absolute; left:200px; top:150px; width:454px; height:134px; z-index:2; visibility: hidden">
Content 2</div>
<div id="Layer3" style="position:absolute; left:200px; top:150px; width:454px; height:134px; z-index:3; visibility: hidden">
Content 3 </div>
<p> </p>
<p>
<select name="type" onchange="Javascript:chkla yer(this.v alue);">
<option value="0">Please Select:</option>
<option value="1">Add a Report</option>
<option value="2">Manage a Report</option>
<option value="3">File Upload snd Report Usage</option>
</select>
</p>
<p> </p>
<p> </p>
</form>
<script language="JavaScript">
function chklayer(v) {
if (v == "0") {
document.getElementById(la yershow).s tyle.visib ility = 'hidden';
document.getElementById(la yerhide).s tyle.visib ility = 'hidden';
return false;
} else if (v == "1") {
layershow = "layer1";
layerhide = "layer2";
layerhide = "layer3";
} else if (v == "2") {
layerhide = "layer1";
layershow = "layer2";
layerhide = "layer3";
} else if (v == "3") {
layershow = "layer3";
layerhide = "layer1";
layerhide = "layer2";
}
document.getElementById(la yershow).s tyle.visib ility = 'visible';
document.getElementById(la yerhide).s tyle.visib ility = 'hidden';
}
</script>
</body>
</html>
What is wrong? Thanks!
Choice 1 shows content in a specified area and hides choice 2,3 , Choice 2 Hides Choice 1 and 3 and shows choice 2, Choice 3 shows Choice three content and hides choice 1 and 2.
Hope this makes sense. I have come close but my content keeps overlapping when the choices are changing.
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form name="form1" method="post" action="">
<div id="Layer1" style="position:absolute; left:200px; top:150px; width:455px; height:131px; z-index:1; visibility: hidden">
Content 1 </div>
<div id="Layer2" style="position:absolute; left:200px; top:150px; width:454px; height:134px; z-index:2; visibility: hidden">
Content 2</div>
<div id="Layer3" style="position:absolute; left:200px; top:150px; width:454px; height:134px; z-index:3; visibility: hidden">
Content 3 </div>
<p> </p>
<p>
<select name="type" onchange="Javascript:chkla
<option value="0">Please Select:</option>
<option value="1">Add a Report</option>
<option value="2">Manage a Report</option>
<option value="3">File Upload snd Report Usage</option>
</select>
</p>
<p> </p>
<p> </p>
</form>
<script language="JavaScript">
function chklayer(v) {
if (v == "0") {
document.getElementById(la
document.getElementById(la
return false;
} else if (v == "1") {
layershow = "layer1";
layerhide = "layer2";
layerhide = "layer3";
} else if (v == "2") {
layerhide = "layer1";
layershow = "layer2";
layerhide = "layer3";
} else if (v == "3") {
layershow = "layer3";
layerhide = "layer1";
layerhide = "layer2";
}
document.getElementById(la
document.getElementById(la
}
</script>
</body>
</html>
What is wrong? Thanks!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I will go through these and give the awards on Monday. Thanks a ton!
ASKER
I split the points as the Reduction in code is always benificial, but the answer by pravinasar was quick and precise. Thanks to both. I really appreciate the help!
You are welcome.
<html>
<head>
<title>Select and Hide</title>
</head>
<body>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<script language="javascript">
function chklayer(v) {
var layerObjs = new Array();
var dispStatus = new Array();
for (ix=1; ix < 4; ix++) {
layerObjs[ix-1] = document.getElementById('L
dispStatus[ix-1] = 'hidden';
}
if (v > 0 && v < 4) {
dispStatus[parseInt(v)-1] = 'visible';
}
for (ix=0; ix < 3; ix++) {
layerObjs[ix].style.visibi
}
if (v == "0") {
return false;
}
return true;
}
</script>
<form name="form1" method="post" action="">
<div id="Layer1" style="position:absolute; left:200px; top:150px; width:455px; height:131px; z-index:1; visibility: hidden">
Content 1 </div>
<div id="Layer2" style="position:absolute; left:200px; top:150px; width:454px; height:134px; z-index:2; visibility: hidden">
Content 2</div>
<div id="Layer3" style="position:absolute; left:200px; top:150px; width:454px; height:134px; z-index:3; visibility: hidden">
Content 3 </div>
<p> </p>
<p>
<select name="type" onchange="Javascript:chkla
<option value="0">Please Select:</option>
<option value="1">Add a Report</option>
<option value="2">Manage a Report</option>
<option value="3">File Upload snd Report Usage</option>
</select>
</p>
<p> </p>
<p> </p>
</form>
</body>
</html>