troopa
08-21-2008, 01:31 PM
Hi, been trying to work this out all day. Basically my aim is to have a country/state chain select that will show the div relevant to the state when you select it.
So if you selected America from the first drop down box it would then show American States in the second drop down box. If you pick a state then it will show a div for that state
(show hide div without chain select)
<script type="text/javascript"><!--
var lastDiv = "";
function showDiv(divName) {
// hide last div
if (lastDiv) {
document.getElementById(lastDiv).className = "hiddenDiv";
}
//if value of the box is not nothing and an object with that name exists, then change the class
if (divName && document.getElementById(divName)) {
document.getElementById(divName).className = "visibleDiv";
lastDiv = divName;
}
}
//-->
</script>
<form id="FormName1" action="blah.php" method="get" name="FormName1">
<select name="selectName" size="1" onchange="showDiv(this.value);">
<option value="">Choose One...</option>
<option value="one">first1</option>
<option value="two">second2</option>
<option value="three">third3</option>
</select>
</form>
</div>
</div>
<div id="storesContent">
<div id="one" class="hiddenDiv"> DIV1 </div>
<div id="two" class="hiddenDiv"> DIV2 </div>
<div id="three" class="hiddenDiv">DIV3</div>
This is the code I am using with 1 dropdown box, which shows a div when you make a selection from the dropdown using an onchange="showDiv(this.value);"
That works fine, trying to combine this with a chain select like:
http://www.dynamicdrive.com/dynamicindex16/chainedselects/index.htm
So when you have picked the last chain option instead of giving an alert or visiting a url it will change the div contents like in the non chain select example above.
I am unfortunately not good with javascript at all, I was sure someone would have done something like this before, however cannot find any examples of it.
So if you selected America from the first drop down box it would then show American States in the second drop down box. If you pick a state then it will show a div for that state
(show hide div without chain select)
<script type="text/javascript"><!--
var lastDiv = "";
function showDiv(divName) {
// hide last div
if (lastDiv) {
document.getElementById(lastDiv).className = "hiddenDiv";
}
//if value of the box is not nothing and an object with that name exists, then change the class
if (divName && document.getElementById(divName)) {
document.getElementById(divName).className = "visibleDiv";
lastDiv = divName;
}
}
//-->
</script>
<form id="FormName1" action="blah.php" method="get" name="FormName1">
<select name="selectName" size="1" onchange="showDiv(this.value);">
<option value="">Choose One...</option>
<option value="one">first1</option>
<option value="two">second2</option>
<option value="three">third3</option>
</select>
</form>
</div>
</div>
<div id="storesContent">
<div id="one" class="hiddenDiv"> DIV1 </div>
<div id="two" class="hiddenDiv"> DIV2 </div>
<div id="three" class="hiddenDiv">DIV3</div>
This is the code I am using with 1 dropdown box, which shows a div when you make a selection from the dropdown using an onchange="showDiv(this.value);"
That works fine, trying to combine this with a chain select like:
http://www.dynamicdrive.com/dynamicindex16/chainedselects/index.htm
So when you have picked the last chain option instead of giving an alert or visiting a url it will change the div contents like in the non chain select example above.
I am unfortunately not good with javascript at all, I was sure someone would have done something like this before, however cannot find any examples of it.