hi, im new to javascript.
i cant get my script to work. I would like that if i type a number in the text box and click the button, it searches in the 2 arrays for the corresponding number and displays in an alert message. for example if I type 2 it should say “Arizona entered the union in 1902”. thanks in advance.
—–Code—-
<html>
<head>
<title>Untitled Document</title>
<script type=”text/javascript”>
<!–
var USStates = new Array(51);
USStates [0] = “Alabama”;
USStates [1] = “Alaska”;
USStates [2] = “Arizona”;
USStates [3] = “Arkansas”;
USStates [4] = “California”;
USStates [5] = “Colorado”;
USStates [6] = “Connecticut”;
USStates [7] = “Delaware”;
USStates [8] = “Florida”;
USStates [9] = “Georgia”;
USStates [10] = “Hawaii”;
USStates [11] = “Idaho”;
USStates [12] = “Illinois”;
USStates [13] = “Indiana”;
USStates [14] = “Iowa”;
USStates [15] = “Kansas”;
USStates [16] = “Kentucky”;
USStates [17] = “Louisiana”;
USStates [18] = “Maine”;
USStates [19] = “Maryland”;
USStates [20] = “Massachusetts”;
USStates [21] = “Michigan”;
USStates [22] = “Minnesota”;
USStates [23] = “Mississippi”;
USStates [24] = “Missouri”;
USStates [25] = “Montana”;
USStates [26] = “Nebraska”;
USStates [27] = “Nevada”;
USStates [28] = “New Hampshire”;
USStates [29] = “New Jersey”;
USStates [30] = “New Mexico”;
USStates [31] = “New York”;
USStates [32] = “North Carolina”;
USStates [33] = “North Dakota”;
USStates [34] = “Ohio”;
USStates [35] = “Oklahoma”;
USStates [36] = “Oregon”;
USStates [37] = “Pennsylvania”;
USStates [38] = “Rhode Island”;
USStates [39] = “South Carolina”;
USStates [40] = “South Dakota”;
USStates [41] = “Tennessee”;
USStates [42] = “Texas”;
USStates [43] = “Utah”;
USStates [44] = “Vermont”;
USStates [45] = “Virginia”;
USStates [46] = “Washington”;
USStates [47] = “West Virginia”;
USStates [48] = “Wisconsin”;
USStates [49] = “Wyoming”;
USStates [50] = “Virgin Islands”;
var stateEntered = new Array(51);
stateEntered [0] = “1900”;
stateEntered [1] = “1901”;
stateEntered [2] = “1902”;
stateEntered [3] = “1903”;
stateEntered [4] = “1904”;
stateEntered [5] = “1905”;
stateEntered [6] = “1906”;
stateEntered [7] = “1907”;
stateEntered [8] = “1908”;
stateEntered [9] = “1909”;
stateEntered [10] = “1910”;
stateEntered [11] = “1911”;
stateEntered [12] = “1912”;
stateEntered [13] = “1913”;
stateEntered [14] = “1914”;
stateEntered [15] = “1915”;
stateEntered [16] = “1916”;
stateEntered [17] = “1917”;
stateEntered [18] = “1918”;
stateEntered [19] = “1919”;
stateEntered [20] = “1920”;
stateEntered [21] = “1921”;
stateEntered [22] = “1922”;
stateEntered [23] = “1923”;
stateEntered [24] = “1924”;
stateEntered [25] = “1925”;
stateEntered [26] = “1926”;
stateEntered [27] = “1927”;
stateEntered [28] = “1928”;
stateEntered [29] = “1929”;
stateEntered [30] = “1930”;
stateEntered [31] = “1931”;
stateEntered [32] = “1932”;
stateEntered [33] = “1933”;
stateEntered [34] = “1934”;
stateEntered [35] = “1935”;
stateEntered [36] = “1936”;
stateEntered [37] = “1937”;
stateEntered [38] = “1938”;
stateEntered [39] = “1939”;
stateEntered [40] = “1940”;
stateEntered [41] = “1950”;
stateEntered [42] = “1951”;
stateEntered [43] = “1952”;
stateEntered [44] = “1953”;
stateEntered [45] = “1954”;
stateEntered [46] = “1955”;
stateEntered [47] = “1956”;
stateEntered [48] = “1957”;
stateEntered [49] = “1958”;
stateEntered [50] = “1959”;
function getStateDate(entry) {
var selectedState = document.getElementById(“entry”).value;
for (var i = 0; i < USStates.length; i++) {
if (USStates[i] == selectedState) {
break;
}
}
alert(selectedState + ” entered the Union in ” + stateEntered[i] + “.”);
}
// –>
</script>
</head>
<body>
<form>
<input type=”text” name=”entry” id=”entry” />
<input type=”button” value=”click” onchange=”getStateDate()” />
</form>
<script type=”text/javascript”>
<!–
// –>
</script>
</body>
</html>