|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Dynamically prepopulating coldfusion multiple selection lists
Hello
I'm trying to prepopulate a multiple selection list with values. The values of the list come from one table in a MySQL database and the values to be selected are fed from another table in the database. Does anybody know how this is done? Basically I need to loop somehow through the table that provides the values to be selected. The table that supplies the values that populate the list is called "regattas", whilst the table that supplies the values to be selected is called "getregattasboatsTB". It is regattasID in both tables that needs to equal one another. The select code is like this: <select name="Regattas" class="Body" size="5" multiple> <option value" "></option></cfoutput> </select> Would appreciate any help on this one. Cheers Moo |
|
#2
|
|||
|
|||
|
What's the actual problem? The code you put up looks like it should populate the select box, except for the brackets being incorrect:
<select name="Regattas" class="Body" size="5" multiple> <option value" "></option> <cfoutput query="Regattas"> <option value="#Regattas.RegattaID#">#Regattas.RegattaName#</option> </cfoutput> </select> So what is it about this code that isn't doing what you want?
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
Yes, I'm afraid this is only so far as I've got!
You're right, this code dynamically populates the list, which I know how to do. I now want to take it a step further by selecting some of the values in this select list. But the values that I want to use come from a separate table in the dbase. I will try to explain further: I'm working on a yachting website. On it there is a search facility for finding boats that are available to take part in various regattas (for people wanting to gain experience of sailing regattas). Each boat is managed by the owner who decides which regattas he/she wants the boats to be available to take part in. So I'm using a select list so that they can select a regatta (or more than 1 regatta) to indicate availability. The regattas are held in one table, boats in another and regattasboats in a third table. The page is obviously a data entry page but I want the select lists to be preselected with the regatta data they entered before for when the owner wishes to update his/her boat details. All this happens on a page that is specific to one boat (the boat data entry/update page). The select list is prepopulated with the regattas that are held in the database of regatta names (values regattaID). I want those regattas that have already been specified for this boat to be already selected (from the table that combines boatIDs with regattaIDs). PS I'm aware of the brackets in the wrong place Thanks Moo |
|
#4
|
|||
|
|||
|
I see, it would be easier to explain the solution if you provided more details about your queries and errors, but I'll give it a shot.
Lets say your query for pre-selecting regattas is called "regattasForYacht" and it contains the fields yachtId, and regattaId. I usually convert the regattaIds to a list, and then do a ListFind to preselect the matches from the generic regatta-list query. To do this, I use a CFIF statement embedded in the <option> tag. Like so... <cfset preselectList = ValueList(regattasForYach.regattaId)> <select name="Regattas" class="Body" size="5" multiple> <option value" "></option> <cfoutput query="Regattas"> <option value="#Regattas.RegattaID#" <cfif ListFind(preselectList,regattas.regattaID>SELECTED</cfif> >#Regattas.RegattaName#</option> </cfoutput> </select> HTH, let me know |
|
#5
|
|||
|
|||
|
Brilliant, Fortunato. That's exactly what I was looking for. Many thanks.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Dynamically prepopulating coldfusion multiple selection lists |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|