...

View Full Version : help with forms/functions



f16fan12
07-07-2006, 04:58 PM
Hi, first post here.
I'm working at NASA as an intern and need to get this code running. The user should be able to select a city from a dropdown list and then it should give them the latitude and longitude of that city. This information is stored in an array, with the first number after the city being the latd and the second number after the city being the latm. For now, I'd just like to display the latd and latm anywhere.
When I try running it it tells me that readform (the function) is not defined. I've tried moving things around in the code, but no luck.
What do you suggest?
Thanks a lot.



<html>
<body>
<script language="JavaScript">


var cities = new Array(
Akron , 41, 5, 0, 81, 30, 0, 266.4, -5.0,
Albany , 42, 39, 0, 73, 45, 0, 83.8, -5.0,
Allentown , 40, 35, 0, 75, 30, 0, 77.7, -5.0,
Atlanta , 33, 44, 0, 84, 23, 0, 307.8, -5.0,
Austin , 30, 16, 0, 97, 44, 0, 182.0, -6.0,
Baltimore , 39, 17, 0, 76, 36, 0, 45.1, -5.0,
Baton Rouge , 30, 27, 0, 91, 9, 0, 17.4, -6.0,
Birmingham , 33, 31, 0, 86, 48, 0, 189.0, -6.0,
Boise , 43, 36, 0, 116, 12, 0, 865.0, -7.0,
Boston , 42, 21, 0, 71, 3, 0, 4.6, -5.0,
Buffalo , 42, 53, 0, 78, 52, 0, 214.9, -5.0,
Charleston , 38, 20, 0, 81, 37, 0, 286.2, -5.0,
Chicago , 41, 51, 0, 87, 39, 0, 185.0, -6.0,
Cincinnati , 39, 9, 0, 84, 27, 0, 264.9, -5.0,
Cleveland , 41, 29, 0, 81, 41, 0, 236.8, -5.0,
Columbia , 34, 0, 0, 81, 2, 0, 57.9, -5.0,
Columbus , 39, 57, 0, 82, 59, 0, 247.5, -5.0,
Dallas , 32, 46, 0, 96, 47, 0, 167.9, -6.0,
Dayton , 39, 45, 0, 84, 15, 0, 175.0, -5.0,
Denver , 39, 44, 0, 104, 59, 0,1610.3, -7.0,
Des Moines , 41, 36, 0, 93, 36, 0, 285.9, -6.0,
Detroit , 42, 20, 0, 83, 3, 0, 192.9, -5.0,
El Paso , 31, 45, 0, 106, 29, 0,1194.2, -7.0,
Flint , 43, 1, 0, 83, 41, 0, 228.6, -5.0,
Grand Rapids , 42, 58, 0, 85, 40, 0, 239.0, -5.0,
Harrisburg , 40, 16, 0, 76, 53, 0, 111.3, -5.0,
Hartford , 41, 46, 0, 72, 41, 0, 51.5, -5.0,
Honolulu , 21, 18, 0, 157, 51, 0, 2.1, -10.0,
Houston , 29, 45, 0, 95, 21, 0, 29.3, -6.0,
Indianapolis , 39, 46, 0, 86, 9, 0, 241.4, -5.0,
Jackson , 32, 17, 0, 90, 11, 0, 88.7, -6.0,
Jacksonville , 30, 19, 0, 81, 39, 0, 6.1, -5.0,
Kansas City , 39, 5, 0, 94, 34, 0, 226.2, -6.0,
Lansing , 42, 43, 0, 84, 33, 0, 253.0, -5.0,
Lincoln , 40, 48, 0, 96, 40, 0, 350.5, -6.0,
Little Rock , 34, 44, 0, 92, 17, 0, 78.3, -6.0,
Los Angeles , 34, 3, 0, 118, 14, 0, 29.6, -8.0,
Louisville , 38, 15, 0, 85, 45, 0, 145.4, -5.0,
Madison , 43, 4, 0, 89, 24, 0, 262.1, -6.0,
Memphis , 35, 8, 0, 90, 2, 0, 78.6, -6.0,
Miami , 25, 46, 0, 80, 11, 0, 2.1, -5.0,
Milwaukee , 43, 2, 0, 87, 54, 0, 204.8, -6.0,
Minneapolis , 44, 58, 0, 93, 15, 0, 254.2, -6.0,
Montgomery , 32, 23, 0, 86, 18, 0, 48.8, -6.0,
Nashville , 36, 9, 0, 86, 47, 0, 179.8, -6.0,
New Haven , 41, 18, 0, 72, 56, 0, 12.2, -5.0,
New Orleans , 29, 57, 0, 90, 4, 0, 0.9, -6.0,
New York , 40, 43, 0, 74, 1, 0, 40.2, -5.0,
Norfolk , 36, 50, 0, 76, 17, 0, 3.0, -5.0,
Oklahoma City , 35, 28, 0, 97, 30, 0, 391.7, -6.0,
Omaha , 41, 15, 0, 95, 56, 0, 303.9, -6.0,
Orlando , 28, 32, 0, 81, 22, 0, 21.3, -5.0,
Philadelphia , 39, 57, 0, 75, 9, 0, 1.5, -5.0,
Phoenix , 33, 26, 0, 112, 4, 0, 340.5, -7.0,
Pittsburgh , 40, 26, 0, 79, 59, 0, 227.7, -5.0,
Portland , 45, 31, 0, 122, 40, 0, 6.4, -8.0,
Providence , 41, 49, 0, 71, 24, 0, 15.5, -5.0,
Raleigh , 35, 46, 0, 78, 38, 0, 132.3, -5.0,
Richmond , 37, 33, 0, 77, 27, 0, 50.0, -5.0,
Riverside , 33, 57, 0, 117, 23, 0, 0.0, -8.0,
Rochester , 43, 9, 0, 77, 36, 0, 166.7, -5.0,
Sacramento , 38, 34, 0, 121, 29, 0, 9.1, -8.0,
St. Paul , 44, 57, 0, 93, 5, 0, 237.7, -6.0,
St. Louis , 38, 37, 0, 90, 11, 0, 163.1, -6.0,
St. Petersburg , 27, 46, 0, 82, 40, 0, 6.1, -5.0,
Salem , 44, 56, 0, 123, 2, 0, 47.2, -8.0,
Salt Lake City , 40, 45, 0, 111, 53, 0,1286.3, -7.0,
San Antonio , 29, 25, 0, 98, 29, 0, 240.2, -6.0,
San Diego , 32, 42, 0, 117, 9, 0, 4.0, -8.0,
San Francisco , 37, 46, 0, 122, 25, 0, 2.4, -8.0,
San Jose , 37, 20, 0, 121, 53, 0, 27.4, -8.0,
Seattle , 47, 36, 0, 122, 19, 0, 121.9, -8.0,
Springfield , 39, 48, 0, 89, 38, 0, 185.9, -6.0,
Syracuse , 43, 2, 0, 76, 8, 0, 125.0, -5.0,
Tallahassee , 30, 26, 0, 84, 16, 0, 45.7, -5.0,
Tampa , 27, 56, 0, 82, 27, 0, 5.8, -5.0,
Toledo , 41, 39, 0, 83, 33, 0, 178.3, -5.0,
Topeka , 39, 2, 0, 95, 40, 0, 283.5, -6.0,
Tulsa , 36, 9, 0, 95, 59, 0, 245.1, -6.0,
Washington , 38, 53, 0, 77, 2, 0, 4.3, -5.0,
)





function readform()
{
var obsvconst
// Get the index for the selected city
obsvconst = 9 * (parseInt(document.citiesform.index.options[document.citiesform.index.selectedIndex].value) - 1)

latd = cities[2 + obsvconst]
latm = cities[3 + obsvconst]

document.write (latd)

}



</script>


<form name="citiesform">
<table border = "0">
<tr>
<td align="right"> City: </td>
<td colspan ="7">


<select name="index" size="1">
<option value="1">Akron </option>
<option value="2">Albany</option>
<option value="3">Allentown</option>
<option value="4">Atlanta</option>
<option value="5">Austin</option>
<option value="6">Baltimore</option>
<option value="7">Baton Rouge </option>
<option value="8">Birmingham</option>
<option value="9">Boise </option>
<option value="10">Boston</option>
<option value="11">Buffalo</option>
<option value="12">Charleston</option>
<option value="13">Chicago</option>
<option value="14">Cincinnati</option>
<option value="15">Cleveland</option>
<option value="16">Columbia </option>
<option value="17">Columbus </option>
<option value="18">Dallas</option>
<option value="19">Dayton</option>
<option value="20">Denver</option>
<option value="21">Des Moines</option>
<option value="22">Detroit</option>
<option value="23">El Paso</option>
<option value="24">Flint </option>
<option value="25">Grand Rapids</option>
<option value="26">Harrisburg</option>
<option value="27">Hartford </option>
<option value="28">Honolulu </option>
<option value="29">Houston</option>
<option value="30">Indianapolis</option>
<option value="31">Jackson</option>
<option value="32">Jacksonville</option>
<option value="33">Kansas City </option>
<option value="34">Lansing</option>
<option value="35">Lincoln</option>
<option value="36">Little Rock </option>
<option value="37">Los Angeles </option>
<option value="38">Louisville</option>
<option value="39">Madison</option>
<option value="40">Memphis</option>
<option value="41">Miami </option>
<option value="42">Milwaukee</option>
<option value="43">Minneapolis </option>
<option value="44">Montgomery</option>
<option value="45">Nashville</option>
<option value="46">New Haven</option>
<option value="47">New Orleans </option>
<option value="48">New York </option>
<option value="49">Norfolk</option>
<option value="50">Oklahoma City</option>
<option value="51">Omaha </option>
<option value="52">Orlando</option>
<option value="53">Philadelphia</option>
<option value="54">Phoenix</option>
<option value="55">Pittsburgh</option>
<option value="56">Portland </option>
<option value="57">Providence</option>
<option value="58">Raleigh</option>
<option value="59">Richmond </option>
<option value="60">Riverside</option>
<option value="61">Rochester</option>
<option value="62">Sacramento</option>
<option value="63">St. Paul </option>
<option value="64">St. Louis</option>
<option value="65">St. Petersburg </option>
<option value="66">Salem </option>
<option value="67">Salt Lake City </option>
<option value="68">San Antonio </option>
<option value="69">San Diego</option>
<option value="70">San Francisco</option>
<option value="71">San Jose </option>
<option value="72">Seattle</option>
<option value="73">Springfield </option>
<option value="74">Syracuse </option>
<option value="75">Tallahassee </option>
<option value="76">Tampa </option>
<option value="77">Toledo</option>
<option value="78">Topeka</option>
<option value="79">Tulsa </option>
<option value="80">Washington</option>
</select>
</td>
</tr>

<tr>
<td colspan="8" align="center">
<input type="button" value=" Click here to do the calculation " onclick="readform()">
</td>
</tr>

<tr>
<td align="right"> Latitude: </td>
<td><input type="text" name="latd" size="10"> deg,</td>
<td><input type="text" name="latm" size="10"> min </td>
</tr>

</table>

</form>

</html>

Sorry if that's a bit long. Most of it is just the city information.

arnyinc
07-07-2006, 05:16 PM
Put quotes around all the city names and make sure you don't have an extra comma on the very last line of your array.




var cities = new Array(
"Akron" , 41, 5, 0, 81, 30, 0, 266.4, -5.0,
"Albany" , 42, 39, 0, 73, 45, 0, 83.8, -5.0,

....

Washington , 38, 53, 0, 77, 2, 0, 4.3, -5.0, //delete this comma
)

f16fan12
07-07-2006, 06:03 PM
Thanks a big bunch for that, arnyinc. I will probably be posting some more questions...I'm trying to modify the script for this page: http://www.chris.obyrne.com/Eclipses/calculator.html
But you've been really helpful, even though it was a small thing. Never knew that though.

f16fan12
07-07-2006, 09:51 PM
Does anybody know how to add a non-selectable break to a drop-down list in a form? Something like, first 10 names are cities in US, second 10 names are cities in Europe, and those two sets of 10 names are divided by a break (a line or something) that the user cannot select.

Thanks.

arnyinc
07-07-2006, 10:39 PM
<form action="form.asp" method="post">
<select id="dropdown" name="dropdown" onchange="if (this.value=='u') { this.selectedIndex=0; } ">
<option></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="u">Unavailable</option>
<option value="3">3</option>
<option value="4">4</option>

</select>
<input type="submit" value="submit" />
</form>

dumpfi
07-08-2006, 05:02 PM
You can group the select options with the optgroup-element, e.g.:


<select name="index" size="1">
<optgroup label="Cities 1-5">
<option value="1">City 1</option>
<option value="2">City 2</option>
<option value="3">City 3</option>
<option value="4">City 4</option>
<option value="5">City 5</option>
</optgroup>
<optgroup label="Cities 6-10">
<option value="6">City 6</option>
<option value="7">City 7</option>
<option value="8">City 8</option>
<option value="9">City 9</option>
<option value="10">City 10</option>
</optgroup>
</select>
dumpfi



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum