Previous Example-|-Next Example-|-Return to Chapter Listing

Example 9.2:
Creating and Checking an Array II

Select the array and position and then click on the button to see what is held in that position:
Select array you want to check:

Select an array position you want to check:

Here's the information in that position:


This is the script we used in the HEAD: <SCRIPT LANGUAGE="JAVASCRIPT"> <!-- // generic object maker prepares an empty array of n items function makeArray(n) { this.length = n for (var i=1; i <= n; i++){ this[i] = null; } return this } // create object listing all the top end of each numeric range var cde = new makeArray(187) var area = new makeArray(187) area[1] = "Alabama "; cde[1] = 205 area[2] = "Alabama "; cde[2] = 334 area[3] = "Alaska "; cde[3] = 907 area[4] = "Alberta "; cde[4] = 403 area[5] = "Antigua "; cde[5] = 268 area[6] = "Arizona "; cde[6] = 520 area[7] = "Arizona "; cde[7] = 602 area[8] = "Arkansas "; cde[8] = 501 area[9] = "Bahamas "; cde[9] = 242 area[10] = "Barbados "; cde[10] = 246 area[11] = "Bermuda "; cde[11] = 441 area[12] = "British Columbia "; cde[12] = 250 area[13] = "British Columbia "; cde[13] = 604 function GetArray(form) { var nBase if (form.array.selectedIndex == 0) sArray = area; if (form.array.selectedIndex == 1) sArray = cde; form.returninfo.value = sArray[form.arraypos.selectedIndex] } //--> </SCRIPT> And this form: <FORM> Select array you want to check: <select name="array" size="2"> <option selected value>area <option>cde </select><P> Select an array position you want to check: <select name="arraypos" size="2"> <option> <option selected value>1 <option>2 <option>3 <option>4 <option>5 <option>6 <option>7 <option>8 <option>9 <option>10 <option>11 <option>12 <option>13 <option>14 </select><P> <INPUT TYPE="button" VALUE="What's in this position?" onclick="GetArray(this.form)"><P> Here's the information in that position: <INPUT TYPE="TEXT" NAME="returninfo"> </FORM>
Previous Example-|-Next Example-|-Return to Chapter Listing