Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help with forms/functions

    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.

    PHP Code:
    <html>
    <
    body>
    <
    script language="JavaScript">


    var 
    cities = new Array(
    Akron                   ,  41,   5,   0,  81,  30,   0266.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,   0307.8,  -5.0
    Austin                  ,  30,  16,   0,  97,  44,   0182.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,   0189.0,  -6.0
    Boise                   ,  43,  36,   0116,  12,   0865.0,  -7.0
    Boston                  ,  42,  21,   0,  71,   3,   0,   4.6,  -5.0
    Buffalo                 ,  42,  53,   0,  78,  52,   0214.9,  -5.0
    Charleston              ,  38,  20,   0,  81,  37,   0286.2,  -5.0
    Chicago                 ,  41,  51,   0,  87,  39,   0185.0,  -6.0
    Cincinnati              ,  39,   9,   0,  84,  27,   0264.9,  -5.0
    Cleveland               ,  41,  29,   0,  81,  41,   0236.8,  -5.0
    Columbia                ,  34,   0,   0,  81,   2,   0,  57.9,  -5.0
    Columbus                ,  39,  57,   0,  82,  59,   0247.5,  -5.0
    Dallas                  ,  32,  46,   0,  96,  47,   0167.9,  -6.0
    Dayton                  ,  39,  45,   0,  84,  15,   0175.0,  -5.0
    Denver                  ,  39,  44,   0104,  59,   0,1610.3,  -7.0
    Des Moines              ,  41,  36,   0,  93,  36,   0285.9,  -6.0
    Detroit                 ,  42,  20,   0,  83,   3,   0192.9,  -5.0
    El Paso                 ,  31,  45,   0106,  29,   0,1194.2,  -7.0
    Flint                   ,  43,   1,   0,  83,  41,   0228.6,  -5.0
    Grand Rapids            ,  42,  58,   0,  85,  40,   0239.0,  -5.0
    Harrisburg              ,  40,  16,   0,  76,  53,   0111.3,  -5.0
    Hartford                ,  41,  46,   0,  72,  41,   0,  51.5,  -5.0
    Honolulu                ,  21,  18,   0157,  51,   0,   2.1, -10.0
    Houston                 ,  29,  45,   0,  95,  21,   0,  29.3,  -6.0
    Indianapolis            ,  39,  46,   0,  86,   9,   0241.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,   0226.2,  -6.0
    Lansing                 ,  42,  43,   0,  84,  33,   0253.0,  -5.0
    Lincoln                 ,  40,  48,   0,  96,  40,   0350.5,  -6.0
    Little Rock             ,  34,  44,   0,  92,  17,   0,  78.3,  -6.0
    Los Angeles             ,  34,   3,   0118,  14,   0,  29.6,  -8.0
    Louisville              ,  38,  15,   0,  85,  45,   0145.4,  -5.0
    Madison                 ,  43,   4,   0,  89,  24,   0262.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,   0204.8,  -6.0
    Minneapolis             ,  44,  58,   0,  93,  15,   0254.2,  -6.0
    Montgomery              ,  32,  23,   0,  86,  18,   0,  48.8,  -6.0
    Nashville               ,  36,   9,   0,  86,  47,   0179.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,   0391.7,  -6.0
    Omaha                   ,  41,  15,   0,  95,  56,   0303.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,   0112,   4,   0340.5,  -7.0
    Pittsburgh              ,  40,  26,   0,  79,  59,   0227.7,  -5.0
    Portland                ,  45,  31,   0122,  40,   0,   6.4,  -8.0
    Providence              ,  41,  49,   0,  71,  24,   0,  15.5,  -5.0
    Raleigh                 ,  35,  46,   0,  78,  38,   0132.3,  -5.0
    Richmond                ,  37,  33,   0,  77,  27,   0,  50.0,  -5.0
    Riverside               ,  33,  57,   0117,  23,   0,   0.0,  -8.0
    Rochester               ,  43,   9,   0,  77,  36,   0166.7,  -5.0
    Sacramento              ,  38,  34,   0121,  29,   0,   9.1,  -8.0
    StPaul                ,  44,  57,   0,  93,   5,   0237.7,  -6.0
    StLouis               ,  38,  37,   0,  90,  11,   0163.1,  -6.0
    StPetersburg          ,  27,  46,   0,  82,  40,   0,   6.1,  -5.0
    Salem                   ,  44,  56,   0123,   2,   0,  47.2,  -8.0
    Salt Lake City          ,  40,  45,   0111,  53,   0,1286.3,  -7.0
    San Antonio             ,  29,  25,   0,  98,  29,   0240.2,  -6.0
    San Diego               ,  32,  42,   0117,   9,   0,   4.0,  -8.0
    San Francisco           ,  37,  46,   0122,  25,   0,   2.4,  -8.0
    San Jose                ,  37,  20,   0121,  53,   0,  27.4,  -8.0
    Seattle                 ,  47,  36,   0122,  19,   0121.9,  -8.0
    Springfield             ,  39,  48,   0,  89,  38,   0185.9,  -6.0
    Syracuse                ,  43,   2,   0,  76,   8,   0125.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,   0178.3,  -5.0
    Topeka                  ,  39,   2,   0,  95,  40,   0283.5,  -6.0
    Tulsa                   ,  36,   9,   0,  95,  59,   0245.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 * (parseInt(document.citiesform.index.options[document.citiesform.index.selectedIndex].value) - 1)

    latd cities[obsvconst]
    latm cities[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.

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    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.

    Code:
    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
    )

  • #3
    New Coder
    Join Date
    Jul 2006
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    New Coder
    Join Date
    Jul 2006
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Code:
    <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>

  • #6
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    You can group the select options with the optgroup-element, e.g.:
    Code:
    <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
    "Failure is not an option. It comes bundled with the software."
    ....../)/)..(\__/).(\(\................../)_/)......
    .....(-.-).(='.'=).(-.-)................(o.O)...../<)
    ....(.).(.)("}_("}(.)(.)...............(.)_(.))Ż/.
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •