Skip to main content
Inspiring
July 31, 2009
Question

Drop Down List Box from an Array?

  • July 31, 2009
  • 3 replies
  • 3094 views

I have an array - a lovely little 1-dimensional array of customer last names - that I want to display in a drop down list box so my user can begin to type a value in that list box and CF will bring up the matching entry.

I have tried cfloop and cfselect, but haven't had any success. Once the user clicks on a name, I want to be able to take that value and do some other processing.

  Any suggestions?

This topic has been closed for replies.

3 replies

sockerdadAuthor
Inspiring
July 31, 2009

I started off using a query:

     <cfquery name = "LastNameQry" datasource = "cfissues">

        SELECT DISTINCT LastName

          FROM Members

         ORDER BY LastName

     </cfquery>

     <cfselect name = "MbrLastName"

               query = "LastNameQry"

               value = "LastName"

               required = "yes">

           </cfselect>

But while the list box performed what I wanted it to do, I couldn't capture the user's selection from this box.  This is necessary because I want to perform a second query that will select first names within the chosen last name.

On the advice of a friend (a Coldfusion programmer), I put the query in a function, then loaded the query results to the before-mentioned session-wide array.  I wondered about using a structure, but that's moot at this point.

Here's how I loaded the array:

1     <cfscript>
2          nameRecordCount = #lastNameVariable.recordcount#;
3          ndx = 1;

4          for (ndx = 1; ndx LTE nameRecordCount; ndx++)
5             {
6               lastNameArray[ndx] = #lastNameVariable.LastName[ndx]#;
7             }

8     </cfscript>

Then I tried a variety of things to load the cfselect:  another loop that used line 6 as the VALUE attribute and just giving the entire array to the value:  Value = #lastNameArray#.

It didn't like either idea.  I swear I heard an evil chuckle as I tried them.

-----------------------

Perhaps my bottom line problem isn't how to load the cfselect, but rather, how to capture the user's selection and save it to a session-wide variable.

Inspiring
July 31, 2009

So you were attempting to load another drop down with all the available first names for the selected last names?

sockerdadAuthor
Inspiring
July 31, 2009

Yes and not yet.  The query successfully gave me all last names, but I couldn't capture the user's selection to execute the second query.  I can't get the array to load the cfselect list box at all.

Don't us CF virgins drive you crazy?

Prompt 1 is for all distinct last names.  Then the selected last name is used to pull all the first names under that particular last name.  Most times, it is just one name, but in several cases there are up to 5 first names for a given last name (and not 'Smith' as you your assume!).

I toyed with the idea of joining the two names in a single query to show "LastName, FirstName" as in Smith, Barney, but it seems a cop-out to give up when I know there is a legitimate solution that I will surely need in other processing.  And besides, even if I did that, I still haven't been able to capture the user's choice!

Inspiring
July 31, 2009

How did you get the array to start with?  Unless you hard coded all the names, you probably don't need it.

Dileep_NR
Inspiring
July 31, 2009

Hi,

Could you give the code you tried?