Dynamic drop down menu?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Haitashi
    New Member
    • Jun 2007
    • 96

    Dynamic drop down menu?

    I want to create a list like Nvidia's menu for selecting drivers.

    The user will select from a list the state and he will get the counties for that state.

    How do I code the states? I believe the best way is to make an array. How do i do that?

    The second menu, the one with the counties should come from a MySQL database table.

    So, if a user selects FLORIDA from the menu that feeds off the array list he will get a second list (or dropdown menu) with ORANGE, SEMINOLE, ...

    The list for those counties are inside a table called COUNTIES in a database called REGISTRATION.

    How can I do this? I've been looking for a comprehensive tutorial and found none :(
  • jsakalos
    New Member
    • Jun 2007
    • 12

    #2
    Wow,

    this is quite a task for a newbie ;)

    Are you using some JavaScript library? You see it is possible to code all Ajax requests and responses handling yoursel but a good Ajax framework (library) makes it much easier.

    Comment

    • Haitashi
      New Member
      • Jun 2007
      • 96

      #3
      I know! I bit of way more than I can handle :P

      I've seen libraries out there like but I wouldn't know how to use them once I download them.

      I don't mind reading, I just can't find info that explains things in simple terms.

      Any library recommendations ?

      Comment

      • jsakalos
        New Member
        • Jun 2007
        • 12

        #4
        I know only one that I use and it is Ext JS library. The community on the forum there is very helpful - helped me a lot when I was starting.

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5390

          #5
          hi ...

          yep ... not a bad task for a newbie ;) ... first let me try to explain how the things would work with ajax (in simple words ;) ) ... and i think ajax is the best way to do that.

          Probably your first menulist should come from a database too ... and so we would create a page that displays the menulist with the states you mentioned. With ajax you would only create a page that has an outline, some divs or other document-nodes, that are used as a container for the data that should be displayed when the user performs any action on the page. so you would call a javascript-function 'onload' of your page, that performs an ajax-request and 'onfinalize' it fills your first menulist with the states. For that purpose you basically need 3 things ... the mentioned function that accepts parameters (servicename, language, whatever you want to pass to the server) and sends the XMLHttpRequest (Post/Get) to the server ... the second: a serverside script (php, asp, whatever) that may be invoked by your request (in our case one or more that performs our SQL-queries that gives us the states, counties, etc.) ... and the third: a callback-function that computes the response from your serverside script. in our case that would be a function that may construct the option-nodes for your menulist, probably you use dom-scripting-methods (createElement, appendChild, ...) for that purpose. so whenever an event occurs in your page you would follow this pattern ... assuming you want to create a good page with the 'ajax-technique' ...

          it is very difficult to show it here with snippets or to show what you have to code ... and there are a lot of tutorials out there, for example:

          AJAX-Tutorial - http://www.w3schools.c om/ajax/ajax_intro.asp

          if you have some things done ... then ask more specific questions here, and we may help you much better ;) ... than with such common hints. But: try an ajax-tutorial before using a framework ... it will greatly help you to understand what happens in the background and it will give you an idea how such frameworks work! ... with that knowledge you will be able to build slick code and applications ... the frameworks out there handle the ajax-requests for you ... of course ... but they give you a bunch of other things too ... mostly a lot of good ui-widgets that you may use for your application ... but for the purpose you have at the moment ... you only need a request, knowledge in dom-scripting, and may be ... if you have to code your serverside for yourself ... knowledge in any serverside-language to create your services there ...

          hope this helps to get you on track to solve your problem ...

          kind regards ...

          ps: don't hesitate to try to handle the XMLHttpRequest with your own code ... ;) i promise ... there is nothing magic or very difficult with that ... but you have to try it for yourself ... you will see ... it is not much to code for this purpose ...

          Comment

          • Haitashi
            New Member
            • Jun 2007
            • 96

            #6
            Thanks for the help guys. My problem is that I'm all theory, no practice. I've read the tutorial.

            I found this tutorial that is exactly what I want except for one thing. The cities drop drown menu is static. I want to call it from a database.

            Chained select boxes

            As I understand it, all I have to do is edit the getCities.php file do that instead of static content, it calls a database.

            I know the theory, I need the specific code that I need to place there. For instance, if the user selects the Florida state, then it should look in the database where state = FL and publish those counties.

            I have a table called cities_counties and the structure is:
            ID
            county
            countyID
            statename
            stateabbreviati on

            Comment

            Working...