View Full Version : Dynamic Dropdown menu problem HELP

08-20-2002, 08:33 AM
Hi All Im getting a bit desperate here so have posted again, as I recieved no help.
I am using the following code in my pages to populate a 2 drop down menus, I cant work out how to get this code to goto the page the choice selects. in the bottom drop down menu.
The code is as follows

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<title>Cascading dropdown lists</title>


<h3>Cascading dropdowns</h3>
Welcome to the wonderful world of cascading dropdowns.
Select a country and the dropdown below will be populated with a selection of regions

<script language='javascript'>

//Author: Paul Berry - PBerry@CirrusSoftware.com
//Date: July 2002
//Licence: Its Freeware!... Just leave my name against the code and send me a mail if you like.
//Purpose: Provides simple dropdown functionality that could be used on multiple cascading dropdown lists.
//Compatability: This process will work on both IE and Netscape (tested on Ns 4.5 and IE 5.5)

var iArrayMax = 16
var aDropdown = new Array(iArrayMax)

//as the page loads - first thing to do is to load the dropdown array
var bOk = LoadArrays()

function LoadArrays()
//this can be thought of as an object array, each element can be identified as a property of the array position
// a very powerful structure for 'client side' data caching.
Array[0] = new sElement('UK','En','England')
Array[1] = new sElement('UK','Ir','Ireland')
Array[2] = new sElement('UK','Sc','Scotland')
Array[3] = new sElement('UK','Wa','Wales')
Array[4] = new sElement('UK','Ia','Isle of Arran')

Array[5] = new sElement('USA','Ny','New York')
Array[6] = new sElement('USA','Il','Illinois')
Array[7] = new sElement('USA','Fl','Florida')
Array[8] = new sElement('USA','Nm','New Mexico')
Array[9] = new sElement('USA','Tx','Texas')
Array[10] = new sElement('USA','Se','Seattle')
Array[11] = new sElement('USA','NJ','New Jersey')
Array[12] = new sElement('USA','VT','Vermont')
Array[13] = new sElement('USA','AZ','Arizona')
Array[14] = new sElement('USA','NH','New Hampshire')
Array[15] = new sElement('USA','MI','Missouri')
Array[16] = new sElement('USA','NE','New England')
Array[17] = new sElement('USA','PA','Pennsylavania')
Array[18] = new sElement('USA','Se','Seattle')

return true

function sElement(sParentId,sValue,sDescription)
// elements that will be loaded into the array structure and persisted
// think of it as an object.
this.ParentId = sParentId
this.Id = sValue
this.Description = sDescription

function bCascadeDrop(oDDsource,oDDdest)
//function to enable cascading dropdowns
//called as the parent dropdown changes.
var iX
var sText
var iY= 0
var sOptionId
var sOptionDesc
var iStartPos

//find the value of the item currently selected
sText = oDDsource.options[oDDsource.selectedIndex].value
if (sText != '0')
//clear down the destination list box
oDDdest.options.length = 0

//loop through the elements that are in the array
// if they match the parent if then they should be displayed.
for (iX=0; iX<=iArrayMax; iX++)
if(sText == Array[iX].ParentId)
//grab the values out of the element (Netscape is not happy doing too many things in a function call!)
sOptionId = Array[iX].Id
sOptionDesc= Array[iX].Description

//write the element into the dripdown box.
oDDdest.options[iY] = new Option (sOptionDesc,sOptionId)
iY = iY +1

<form action="FrmNew">
<select style="width=150" name="sCountry" onChange="bCascadeDrop(this, document.forms[0].sRegion)">
<option value="0" SELECTED> - None selected - </option>
<option value="UK" > United Kingdom</option>
<option value="USA">America</option>
<select name="sRegion" style="width=150">
<option value="0" SELECTED> - None selected - </option>



Roy Sinclair
08-20-2002, 02:25 PM
What page the "choice" selects. You have no pages referenced at all in your code. It looks to me like you took some code to populate one select from a selection made in another select but that doesn't make the selects into navigation.

08-20-2002, 10:20 PM
is this what you're describing?

08-21-2002, 12:27 AM
Thanks speedracer thats it. bloody marvelous