The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 4 of 4

Thread: Form with country and state fields from MySQL database

  1. #1

    Pallete Form with country and state fields from MySQL database

    Helo everybody!

    I'm trying to find a code for implementing in a php form. The form must contain two selects: one for a country and one for the state. All the data is taken from a database.

    I suppose ajax and javascript are needed... because I want that the second select autopopulate depending on the value selected in the first select: country.

    I can't believe there is no code with this solution.

    any ideas?

    Thank you!

  2. #2
    Of course there's a code, you just have to do it yourself!
    AJAX would be good.
    Grab the value of the select with an onchange event, send it to the server, query the database, send back the values for the second select box.
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

  3. #3

    Fla Box

    Thank you, I will try doing it by myself. Best regards.

  4. #4
    If there's not too much data, you can load it all on one page, but hide from user with help of CSS:

    <select name="USA_states" style="visibility:hidden">
    <option value="AZ">Arizona
    <option value="TX">Texas
    ...
    </select>

    You can put such hidden SELECT-s for all countries on a single page.
    Then make use of JavaScript to show the right SELECT for a state, when user selects a country:

    <select name=country onchange=countryChanged(this.value)>
    <option value=USA>United States
    <option value=Canada>Canada
    ...
    </select>

    Depending on the value, you can show/hide the right state SELECT:

    forms[0].elements[country+"_select"].style.visibility = ''; // shows
    forms[0].elements[country+"_select"].style.visibility = 'hidden'; // hides

    Good luck!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012