EasyCFM.COM ColdFusion Forums / ColdFusion Applications / multi select list box

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: multi select list box

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

marcnz
08-06-2007 @ 8:11 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 2
Joined: Aug 2007

I am working on a page that allow addition or edition of a customer. The customer can belong to more than one company. I have 3 tables: customer, companies, customer_companies that hold the multi criteria, ie same custid with different companyid.
I can have a <cfselect> to show all the company names and the multi selection works. The problem I have is that I want the list to have the existing companies automatically selected when in edit mode. Has to be none selected when in addition mode.
Here is what I have so far:

<cfselect name="Company"
     required="yes"
     message="Please select a company for this customer"
     size="50"
     multiple="yes"
     query="getAllSuppliers"
     value="#getAllSuppliers.ContactID#"
     display="#getAllSuppliers.Supplier#">
</cfselect>     

I have two queries: one to populate the company list box with all the existing companies and one to get all the companies attached with the custid:

<cfif isDefined("URL.id")>
<cfquery name="editCustomer" datasource="datasource">
SELECT * FROM calmweb_CustFinal WHERE Custid = #URL.id#;
</cfquery>
</cfif>     

and:

<cfquery name="getAllSuppliers" datasource="datasource">
SELECT * FROM calmweb_SuppliersAndCustomers ORDER BY Supplier
</cfquery>

Any help would be much appreciated.

anitha
08-14-2007 @ 9:59 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 1
Joined: Aug 2007

Hi,
  I am working on a very similar case. I tried cfloop surrounding the option ,Some thing like this.

<cfquery name="get_site1_docs" datasource="#datasource#">
          SELECT     SiteArea, DocumentStructure, DocumentCategory, SiteStructureCategoryid
          FROM         SiteStructure_Lookup
          WHERE     (SiteID = 1) AND (DeleteFlag = 0)
          ORDER BY SiteArea, DocumentStructure, DocumentCategory
          </cfquery>
          <cfquery name="get_site1_docs1" datasource="#datasource#">
          SELECT     ss.SiteArea, ss.DocumentStructure, ss.DocumentCategory, ss.SiteStructureCategoryid,ds.documentstructureid
          FROM         SiteStructure_Lookup ss,documentstructure ds
          WHERE     ss.SiteStructureCategoryid = ds.SiteStructureCategoryid
          and (ss.SiteID = 1) AND (ss.DeleteFlag = 0)
          and ds.documentid = #getfieldinfo.documentid#
          ORDER BY ss.SiteArea, ss.DocumentStructure, ss.DocumentCategory
          </cfquery>               
          <cfselect name="site1_documentstructureid" id="site1_documentstructureid" display="DocumentCategory" query="get_site1_docs"  value="SiteStructureCategoryid" group="DocumentStructure" queryPosition="Below" multiple="yes" size="10" width="10">
          <option value="">Select SiteArea/Topic/SubTopic</option>
<cfif  IsDefined ("getfieldinfo.documentid") and #getfieldinfo.documentid# neq "">
<cfloop query="get_site1_docs1">
          <option value="#get_site1_docs.SiteStructureCategoryid#" selected>#get_site1_docs1.DocumentCategory#</option>
</cfloop>
          <cfelse>
          <option value="">#get_site1_docs1.DocumentCategory#<option>
          </cfif>          
          </cfselect>

marcnz
08-14-2007 @ 5:36 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 2
Joined: Aug 2007

Solution has been found for me on another forum:

<!--- make a comma separated list of CC_contactid's from custCompanies query --->
<cfset theList = valuelist(custCompanies.CC_contactid)>

               <cfoutput query="getAllSuppliers">
<cfif listfindnocase(theList,getAllsuppliers.contactid)>
<cfset ischecked = true>
<cfelse>
<cfset ischecked = false>
</cfif>
                <!--- only want to display 4 companies and checkboxes on one row --->
                <cfif iCol LTE 4>
                <td width="10">
                  <cfinput type="checkbox"
                    name="SUP_#g etAllSuppliers.Contactid#"
                    value="no" checked='#ischecked#'>
                </td>
                <td width="115">#getAllSuppliers.Supplier#</td>
                <cfelse>
                </tr>
                  <cfset iCol = 1>
                  <tr>
                   <td width="10">
                    <cfinput type="checkbox"
                    name="SUP_#g etAllSuppliers.Contactid#"
                    value="no" checked='#ischecked#'>                        </td>
                   <td width="115">#getAllSuppliers.Supplier#</td>
                </cfif>     ;  &nbs p;    
                <!--- always increment the column by 1 --->
                <cfset iCol = iCol + 1>
               </cfoutput>


Maybe this will also help others. It works very well.


Website Designed and Developed by Pablo Varando.