Create state-cty dropdown lists

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marc

    Create state-cty dropdown lists

    I've gotten everything up and running except for this -- I'd like to
    be able to have people have a dropdown list of cities in the US to use
    (or wherever) and not have to input them manually into a text field.
    When you do then there are issues of misspellings, etc.

    Now I have a list of cities from each state that is a sample that
    works in an html page. Problem is that it takes up 2 MB! Way too much
    to load on a single page and I was wondering how this is accomplished
    best -- do people use javascripts that can pull information from
    another flat flie? Do people use PHP to connect to a mysql database
    that might have a list of these fields and then reloads the page?

    I'm really not sure of best options and would be grateful for anyone
    to give me pointers or whether there are other examples and even
    places to buy these databases (not likely but good to have if I decide
    to do so.)
  • Fletch

    #2
    Re: Create state-cty dropdown lists

    Marc wrote:
    [color=blue]
    > I've gotten everything up and running except for this -- I'd like to
    > be able to have people have a dropdown list of cities in the US to use
    > (or wherever) and not have to input them manually into a text field.
    > When you do then there are issues of misspellings, etc.
    >
    > Now I have a list of cities from each state that is a sample that
    > works in an html page. Problem is that it takes up 2 MB! Way too much
    > to load on a single page and I was wondering how this is accomplished
    > best -- do people use javascripts that can pull information from
    > another flat flie? Do people use PHP to connect to a mysql database
    > that might have a list of these fields and then reloads the page?
    >
    > I'm really not sure of best options and would be grateful for anyone
    > to give me pointers or whether there are other examples and even
    > places to buy these databases (not likely but good to have if I decide
    > to do so.)[/color]


    /*does all processing on genenric amounts of linked selects!!!
    <script type="text/javascript">
    <!--
    selects=new Array();
    selects[0]=document.forms['FrmAdminContro l'].elements['test.0'];
    selects[1]=document.forms['FrmAdminContro l'].elements['test.1'];
    selects[2]=document.forms['FrmAdminContro l'].elements['test.2'];

    initLinkedSelec t(selects);
    -->

    requires following names on options so we know what goes where

    <select name"=test.0">
    <option value="dog">Dog </option>
    <option value="cat">Cat </option>
    </select>
    <select name="test.1">
    <option value="dog-fido">Fido</option>
    <option value="dog-rover">Rover</option>
    <option value="cat-boots">Boots</option>
    <option value="cat-pussy">Pussy</option>
    </select>
    <select> name="test.2">
    <option value="dog-fido-dead">Dead</options>
    ....
    ....
    </select>
    */

    function initLinkedSelec t(selects) {
    var options = new Array();
    var nextselect = new Array();
    for (k = selects.length-2 ; k >= 0 ; k-- ){
    from=selects[k];
    to=selects[k+1];
    options[from.name]=new Array();
    (from.style || from).visibilit y = "visible";
    for (var i=0; i < to.options.leng th; i++) {
    options[from.name][i] = new
    Array(to.option s[i].text,to.option s[i].value);
    }

    nextselect[from.name]=k;
    from.onchange = function() {
    to=selects[nextselect[this.name]+1];
    var fromCode = this.options[this.selectedIn dex].value+'-';
    var selectedoption= 0;
    selectedoption= to.options[to.selectedInde x].text;
    to.options.leng th = 0;
    for (i = 0; i < options[this.name].length; i++) {
    if (options[this.name][i][1].indexOf(fromCo de) == 0) {
    to.options[to.options.leng th] = new Option(options[this.name][i
    [0],options[this.name][i][1]);
    if(options[this.name][i][0]==selectedoptio n)
    to.options[to.options.leng th-1].selected=true;
    }
    }
    // to.options[selectedoption].selected = true;
    if(selects[nextselect[to.name]] && selects[nextselect[to.name]].onchange
    {
    selects[nextselect[to.name]].onchange();
    } else {

    }
    }
    from.onchange() ;
    }
    }




    --
    Fletch
    A: Because it disrupts the natural flow when reading
    Q: Why is it bad to top post?

    Comment

    • Tim Roberts

      #3
      Re: Create state-cty dropdown lists

      Marc <narc@quark.com > wrote:[color=blue]
      >
      >I've gotten everything up and running except for this -- I'd like to
      >be able to have people have a dropdown list of cities in the US to use
      >(or wherever) and not have to input them manually into a text field.
      >When you do then there are issues of misspellings, etc.[/color]

      Yes, but that's the only practical option. There will always be city names
      (old names, variations, new names) that you don't have in your list. Will
      you be able to handle Canadian cities, or European cities?
      [color=blue]
      >Now I have a list of cities from each state that is a sample that
      >works in an html page. Problem is that it takes up 2 MB! Way too much
      >to load on a single page and I was wondering how this is accomplished
      >best -- do people use javascripts that can pull information from
      >another flat flie? Do people use PHP to connect to a mysql database
      >that might have a list of these fields and then reloads the page?[/color]

      No. People do not use dropdown lists for cities for precisely this reason.

      If you're willing to pay the price for a zip code service, you could have
      the user enter a zip code, then look up the cities and states for that zip
      code, and present THOSE in a list. It would require a server round-trip,
      but there are usually no more than a half-dozen city names for any single
      zip.

      Overall, it's probably easier to have users enter the city names they like,
      and validate them later through the post office.
      --
      - Tim Roberts, timr@probo.com
      Providenza & Boekelheide, Inc.

      Comment

      • Mike

        #4
        Re: Create state-cty dropdown lists

        On Tue, 22 Feb 2005 23:19:52 -0800, Tim Roberts <timr@probo.com >
        wrote:
        [color=blue]
        >Marc <narc@quark.com > wrote:[color=green]
        >>
        >>I've gotten everything up and running except for this -- I'd like to
        >>be able to have people have a dropdown list of cities in the US to use
        >>(or wherever) and not have to input them manually into a text field.
        >>When you do then there are issues of misspellings, etc.[/color]
        >
        >Yes, but that's the only practical option. There will always be city names
        >(old names, variations, new names) that you don't have in your list. Will
        >you be able to handle Canadian cities, or European cities?
        >[color=green]
        >>Now I have a list of cities from each state that is a sample that
        >>works in an html page. Problem is that it takes up 2 MB! Way too much
        >>to load on a single page and I was wondering how this is accomplished
        >>best -- do people use javascripts that can pull information from
        >>another flat flie? Do people use PHP to connect to a mysql database
        >>that might have a list of these fields and then reloads the page?[/color]
        >
        >No. People do not use dropdown lists for cities for precisely this reason.
        >
        >If you're willing to pay the price for a zip code service, you could have
        >the user enter a zip code, then look up the cities and states for that zip
        >code, and present THOSE in a list. It would require a server round-trip,
        >but there are usually no more than a half-dozen city names for any single
        >zip.
        >
        >Overall, it's probably easier to have users enter the city names they like,
        >and validate them later through the post office.[/color]

        Impossible. Too much work, plus the cleanup for misspellings would
        make this a bear of a task. I could always use zip codes but then the
        cities aren't really accurate in some instances since you can have
        several different "towns" in one zip code. Not catastrophic but it
        would be nice if this were easier.

        Now I'd have to worry about dealing with putting an entire database of
        zip codes into my database plus build in queries to join the zip code
        table with the user table. I could always write a query to search the
        zip code database and enter the town name into the user table for,
        e.g. user.city to match user.zipcode . The fun part begins when you
        want to perform a search and want the user to be able to choose by
        city instead of just a zip code so I still have the issue of finding
        the city name list for a drop down for users to search...

        Comment

        • Matt Mitchell

          #5
          Re: Create state-cty dropdown lists

          "Mike" <tkd__REM_OVE_S PA_M_inthecity@ yahoo__SPAM_.co m> wrote in message
          news:aoio11dp40 1pck8lakdjgs3vr ufimktpeh@4ax.c om...

          : Impossible. Too much work, plus the cleanup for misspellings would
          : make this a bear of a task. I could always use zip codes but then the
          : cities aren't really accurate in some instances since you can have
          : several different "towns" in one zip code. Not catastrophic but it
          : would be nice if this were easier.
          :
          : Now I'd have to worry about dealing with putting an entire database of
          : zip codes into my database plus build in queries to join the zip code
          : table with the user table. I could always write a query to search the
          : zip code database and enter the town name into the user table for,
          : e.g. user.city to match user.zipcode . The fun part begins when you
          : want to perform a search and want the user to be able to choose by
          : city instead of just a zip code so I still have the issue of finding
          : the city name list for a drop down for users to search...

          I missed the OP, but you'll need to do this on two pages (you could use an
          IFRAME if you really *had* to I suppose...)

          This is assuming you're selecting data from an existing list - it's no good
          for inputting a new address.

          1 - User selects state
          2 - Submit form
          3 - Return list of towns matching that state

          As you said, a 2MB page is not practical, and no-one will thank you for it.

          Matt


          Comment

          Working...