Skip to main content
August 28, 2008
Question

Dynamic dropdown

  • August 28, 2008
  • 12 replies
  • 1487 views
I can't test this because I don't have a server running. But I do want to know if this will work. I'm trying to populate a dropdown based on another dropdown's value...

<select name="test_select">
<option selected value=""></option>
<option value="bill">bill</option>
<option value="john">john</option>
<option value="andy">andy</option>
</select>

<cfif IsDefined(#form.test_select#)>
<cfquery name="test_select" datasource="mydsn" maxrows="25">
SELECT id,first_name,last_name FROM my_db WHERE first_name = '#test_select#'
</cfquery>
<select name="first_name">
<cfoutput query="test_select">
<option value="#id#">#first_name# #last_name#</option>
</cfoutput>
</select>
</cfif>
    This topic has been closed for replies.

    12 replies

    August 28, 2008
    I should have said that upfront. CF7. I am beginning to hate CF7 based on all the new stuff that came out with 8. cfimage is one and ajax functions are another.

    I need a solution for cf7.

    Inspiring
    August 28, 2008
    idesdema wrote:
    > I can't test this because I don't have a server running. But I do want to know
    > if this will work. I'm trying to populate a dropdown based on another
    > dropdown's value...
    >

    After the form is submitted with the an option in the first select
    control hightlighted.

    But nothing is going to happen on the users Client machine because
    ColdFusion is not running there, it is running on the server and has no
    idea what the user maybe doing with that control until it receives
    another request.

    What you are doing is a standard 'Two Related Selects' and there are
    many documented and plug and play solutions out there. If your data set
    is small enough you can send it all in one response and allow JavaScript
    to build and populate the second Select based on the first value.

    Otherwise you can use JavaScript and ColdFusion with AJAX techniques to
    hide the requests to get the second Selects options from the user behind
    the scenes.
    August 28, 2008
    I have done a dropdown like that using javascript and a small data set. However, this is going to be far more complex. I'd need to have 50 arrays.

    Specifically, when a users selects a state in the first dropdown, the second dropdown needs to populate with all the rivers in that state. You mentioned a framework towards the end of your post that I'd like to explore. Do you have any tutorials or links you can pass to me or should I just start searching on google?