View Full Version : Help to customise this code

08-19-2002, 07:36 AM
I have used this code from one of the java source sites, however Im having trouble working out how to get it to go to the page when selected

<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 = 25
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('1ST','students/students.htm','Students')

Array[1] = new sElement('2PA','paents/parents.htm','For Parents')
Array[2] = new sElement('2PA','parents/enrolment.htm','Enrolment Information')
Array[3] = new sElement('2PA','parents/faq.htm','F.A.Q')
Array[4] = new sElement('2PA','parents/unifroms.htm','Uniforms')
Array[5] = new sElement('2PA','parents/decision.htm','School Decision Group')
Array[6] = new sElement('2PA','parents/citiens.htm','P & C')
Array[7] = new sElement('2PA','parents/cost.htm','Contributios & Charges')

Array[8] = new sElement('3AB','about/plans.htm','Plans & Maps')
Array[9] = new sElement('3AB','about/photos.htm','Photos')
Array[10] = new sElement('3AB','about/philosophy.htm','Philosophy')

Array[11] = new sElement('4LE','staff/staff.htm','For Staff')

Array[12] = new sElement('5FA','community/community.htm','Community Facilities')
Array[13] = new sElement('5FA','community/libary.htm','Libary')
Array[14] = new sElement('5FA','community/recreation.htm','Recreaion Center')

Array[15] = new sElement('6NE','news/news.htm','News & Events')
Array[16] = new sElement('6NE','news/newsletter.htm','Nwsletters')
Array[17] = new sElement('6NE','news/meetings.htm','Meetings')
Array[18] = new sElement('6NE','news/principle.htm','Principles Desk')

Array[19] = new sElement('7SL','school/policy.htm','School Policies')

Array[20] = new sElement('8ST','staff/staff.htm','For Staff')

Array[21] = new sElement('9EM','jobs/jobs.htm','Employment')
Array[22] = new sElement('9EM','jobs/teaching.htm','Teaching')
Array[23] = new sElement('9EM','community/nonteching.htm','Non - Teching')

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 drpdown box.
oDDdest.options[iY] = new Option (sOptionDesc,sOptionId)
iY = iY +1
<form action="FrmNew1" name="form1">
<select style="width=150" name="sCountry" onChange="bCascadeDrop(this, document.forms[0].sRegion)">
<option value="0" SELECTED> - Menu Selection - </option>
<option value="1ST" > For Students</option>
<option value="2PA">For Parents</option>
<option value="3AB">About Us</option>
<option value="4LE">Learning Communities</option>
<option value="5FA">Community Facilities</option>
<option value="6NE">News & Events</option>
<option value="7SC">School Policies</option>
<option value="8ST">For Staff</option>
<option value="9EM">Employment opportunities</option>
<select name="sRegion" style="width=150">
<option value="0" SELECTED> - None selected - </option>

<input type="button" name="test" value="Go!"
onChange="bCascadeDrop(this, document.forms[0].sRegion)">