Kilgannon
01-23-2012, 12:52 PM
Hi all,
Only recently started, self-teaching, html and Java in order to get a project idea of mine up and running.
First barrier I've come across is trying to sort out a drop down with search button that will then reveal the connected hidden div, I've mangled together some code from a couple of sources with what I've learnt, but not really sure how to tie in the "Search" button to the showDiv(divname) function. Wondering if anyone could help out.
Many thanks in advance
<head>
<title>Untitled</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
<script type="text/javascript"><!--
var lastDiv = "";
function showDiv(divname) {
if (lastDiv) {
document.getElementById(lastDiv).className = "hiddenDiv";
}
if (divName && document.getElementById(divName)) {
document.getElementById(divName).className = "visibleDiv";
lastDiv = divName;
}
}
</script>
</head>
<body>
<h1>
<form name="form" >
<select name="select">
<option selected>Choose
<option value="one"> one
<option value="two"> two
<option value="other"> other
</select>
<input type="button" value="Search" onClick="showDiv(this.value)">
</form>
</h1></br>
<h2>
Results:
<p id="one" class="hiddenDiv">one</p>
<p id="two" class="hiddenDiv">two</p>
<p id="other" class="hiddenDiv">other</p>
</h2>
</body>
</html>
From my stylesheet:
.hiddenDiv {
display: none;
}
.visibleDiv {
display: block;
}
Only recently started, self-teaching, html and Java in order to get a project idea of mine up and running.
First barrier I've come across is trying to sort out a drop down with search button that will then reveal the connected hidden div, I've mangled together some code from a couple of sources with what I've learnt, but not really sure how to tie in the "Search" button to the showDiv(divname) function. Wondering if anyone could help out.
Many thanks in advance
<head>
<title>Untitled</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
<script type="text/javascript"><!--
var lastDiv = "";
function showDiv(divname) {
if (lastDiv) {
document.getElementById(lastDiv).className = "hiddenDiv";
}
if (divName && document.getElementById(divName)) {
document.getElementById(divName).className = "visibleDiv";
lastDiv = divName;
}
}
</script>
</head>
<body>
<h1>
<form name="form" >
<select name="select">
<option selected>Choose
<option value="one"> one
<option value="two"> two
<option value="other"> other
</select>
<input type="button" value="Search" onClick="showDiv(this.value)">
</form>
</h1></br>
<h2>
Results:
<p id="one" class="hiddenDiv">one</p>
<p id="two" class="hiddenDiv">two</p>
<p id="other" class="hiddenDiv">other</p>
</h2>
</body>
</html>
From my stylesheet:
.hiddenDiv {
display: none;
}
.visibleDiv {
display: block;
}