A Simple Parallel Array Lookup
/*
JavaScript Bible, Fourth Edition
by Danny Goodman
John Wiley & Sons CopyRight 2001
*/
<HTML>
<HEAD>
<TITLE>Parallel Array Lookup</TITLE>
<SCRIPT LANGUAGE="JavaScript">
// the data
var regionalOffices = new Array("New York", "Chicago", "Houston", "Portland")
var regionalManagers = new Array("Shirley Smith", "Todd Gaston", "Leslie Jones", "Harold Zoot")
var regOfficeQuotas = new Array(300000, 250000, 350000, 225000)
// do the lookup into parallel arrays
function getData(form) {
var i = form.offices.selectedIndex
form.manager.value = regionalManagers[i]
form.quota.value = regOfficeQuotas[i]
}
</SCRIPT>
</HEAD>
<BODY onLoad="getData(document.officeData)">
<H1>Parallel Array Lookup</H1>
<HR>
<FORM NAME="officeData">
<P>
Select a regional office:
<SELECT NAME="offices" onChange="getData(this.form)">
<OPTION>New York
<OPTION>Chicago
<OPTION>Houston
<OPTION>Portland
</SELECT>
</P><P>
The manager is:
<INPUT TYPE="text" NAME="manager" SIZE=35>
<BR>
The office quota is:
<INPUT TYPE="text" NAME="quota" SIZE=8>
</P>
</FORM>
</BODY>
</HTML>
Related examples in the same category