/    Sign up×
Community /Pin to ProfileBookmark

Interdependent Select Boxes

Can you make one of these in PHP or just in Javascript

to post a comment
PHP

23 Comments(s)

Copy linkTweet thisAlerts:
@bubbisthedogAug 22.2007 — Either. Doing post-backs, PHP can dynamically build the lists. You can use the DOM to build lists dynamically in JavaScript, not to mention that you can use AJAX to build lists dynamically. A fairly simple search engine query should show you how to do it any of these ways.
Copy linkTweet thisAlerts:
@JavajoobauthorAug 22.2007 — Ah well mine my form is validated by PHP. One dynamic box will spawn another which has to be chosen. Also when another choice is made is form 2identical DOB boxes rather than one. Which would you reccomend?
Copy linkTweet thisAlerts:
@bubbisthedogAug 22.2007 — Totally depends on the situation. Most of the time, when dealing with database data, I'll use PHP, which, of course, requires a complete post-back to the server; but that depends what else is on the page, etc. Often, I find, it's just a judgment call. AJAX is a route that I've taken at times, but only for very specific purposes, such as when a user selects a state, I'll populate another drop-down with counties in that state. AJAX doesn't require entire-page post-backs, virtually like client-side functionality; but I would be careful not to get carried away with it.
Copy linkTweet thisAlerts:
@JavajoobauthorAug 22.2007 — Is there a specific tutorial for making a PHP dynamic select box? My next options might be AJAX and Javascript
Copy linkTweet thisAlerts:
@bubbisthedogAug 22.2007 — If you understand

[LIST]
  • [*]$_POST[] and $_GET[]

  • [*]SQL querying and fetching in PHP

  • [*]writing drop-down lists based on fetched results

  • [/LIST]


    then you can create dynamic PHP drop-downs. I'd suggest researching something like 'create drop-down PHP SQL'.
    Copy linkTweet thisAlerts:
    @bokehAug 22.2007 — You don't need AJAX for a chained select, just javascript. And if they don't have javascript enabled just run the page without the chaining.
    Copy linkTweet thisAlerts:
    @JavajoobauthorAug 22.2007 — These dynamic boxes are quite important. I should read up on it is this has gotten confusing. AJAX or Javascript or PHP. It can be done with arrays can't it?
    Copy linkTweet thisAlerts:
    @bokehAug 23.2007 — It can be done with arrays can't it?[/QUOTE]Yes! What data are you using?
    Copy linkTweet thisAlerts:
    @JavajoobauthorAug 23.2007 — Well they are select boxes. As an example with countrys: if America is chosen there emerges a box where states must be chosen. And if Canada, provinces. I suppose you chould say text or string data
    Copy linkTweet thisAlerts:
    @bokehAug 23.2007 — I was asking for the dataset not an example.
    Copy linkTweet thisAlerts:
    @bubbisthedogAug 23.2007 — I should read up on it is this has gotten confusing.[/QUOTE]
    I suggested searching 'create drop-down PHP SQL.' I just searched it using Google and the found several approaches at performing this task on the first couple of pages.

    I also went a step further and searched 'create dependent drop-downs JavaScript': http://www.felgall.com/jstip22.htm (an approach from a helpful gentleman who participates in this forum). And there are more examples if search for a few minutes.

    My point is that a few searches would tell you what you want to know in order to get started. You're going to have to mess around with these approaches and get used to how they function in order to apply them to your tasks at hand.
    Copy linkTweet thisAlerts:
    @JavajoobauthorAug 23.2007 — By dataset are you referring to the database?

    And the PHP method was only explained vaguely to me so I wasn't too sure how to elaborate on it. Thank you for this current information
    Copy linkTweet thisAlerts:
    @JavajoobauthorAug 23.2007 — As for the database part there will be a column in the table that accepts the information from the dependant box
    Copy linkTweet thisAlerts:
    @bokehAug 23.2007 — The reason I am asking about the data is because it is impossible to give you a relevant answer without it.
    Copy linkTweet thisAlerts:
    @JavajoobauthorAug 23.2007 — Ok I must ask: Exatly what do you need in the database (MySQL) to form one of these PHP dynamic boxes?
    Copy linkTweet thisAlerts:
    @bokehAug 23.2007 — Exatly what do you need in the database[/QUOTE]I was trying to offer you relevant help but if you want to keep something that is going to be displayed on a public website "top secret" that's up to you.
    Copy linkTweet thisAlerts:
    @JavajoobauthorAug 23.2007 — Oh its just I heard you need to do something in the database to have the dynamic box.


    Also do you need to see how the table would look itself? I could it privately
    Copy linkTweet thisAlerts:
    @bokehAug 23.2007 — It depends on the size and complexity of the data. If the data is basic (just a few hundred items) you don't need AJAX since all the required data to implement a chained select can be passed on initial load.
    Copy linkTweet thisAlerts:
    @JavajoobauthorAug 23.2007 — Well there won't more than 100 items being sent to the database from the form
    Copy linkTweet thisAlerts:
    @bokehAug 23.2007 — I'm asking about the chained select, not what data people will enter into the form. How many groups will there be and how many items in each group?
    Copy linkTweet thisAlerts:
    @JavajoobauthorAug 23.2007 — Aah. Well not hundreds but as I mentioned before there is the country box. Then the state box if America is chosen (50). And the province box for Canada and so on. Maybe over 100 but not hundreds.


    Also there is another box which will indicate whether one or two people are submitting the form. At which point one or two DOB boxes must emerge. Also not hundreds
    Copy linkTweet thisAlerts:
    @bokehAug 23.2007 — Well it's just a very small amount of fixed data that is not time-linked so there is absolutely no reason to use AJAX.

    How I would do it is put the countries in the first drop-down and all the States and Provinces in the second. That way it will be usable without Javascript. But if they do have Javascript enabled use it to rebuild the second drop-down based on what is in the first. The code to do this is pretty basic.
    Copy linkTweet thisAlerts:
    @JavajoobauthorAug 23.2007 — I believe it can be done with arrays
    ×

    Success!

    Help @Javajoob spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.27,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...