Solved

Auto Select Cfselect tag

Posted on 2009-05-16
3
300 Views
Last Modified: 2013-12-24
I currently have a cfselect tag that is populated via a query. I'm trying to get the queried results to automatically select an entry based upon a condition (url.contactid).
QUESTION: How do I get the cfselect tag to automatically select an entry base upon a variable either URL or FORM?


<cfselect name="ContactID" size="25" id="ContactID"> <cfoutput query="contacts">

          <option value="#contacts.ContactID#">#contacts.LastName#, #contacts.FirstName# - #contacts.EmailAddress# ---  #contacts.Company#</option>

        </cfoutput> </cfselect>

Open in new window

0
Comment
Question by:jasch2244
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
azadisaryev earned 500 total points
ID: 24404627
like this:

<cfselect name="ContactID" size="25" id="ContactID">
<cfoutput query="contacts">
  <option value="#contacts.ContactID#" <cfif contacts.contactID EQ SomeValriable>selected="selected"</cfif>>#contacts.LastName#, #contacts.FirstName# - #contacts.EmailAddress# ---  #contacts.Company#</option>
</cfoutput>
</cfselect>

or, if you edited your query and added a new column by concatenating all the column you use in your select's display values, then you could just use 1 line of code to create your cfselect:

<cfselect name="contactID" size="25" QUERY="contacts" DISPLAY="concatenated-qiery-column-name" VALUE="contactID" SELECTED="#SomeVariable#"></cfselect>

Azadi
0
 
LVL 1

Author Comment

by:jasch2244
ID: 24404727
Does the "selected" portion of the code refer to a variable as well? example: selected="selected"
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24405054
no, selected="selected" is just a standard XHTML way to mark a selected option. it is not any cf variable.
you can just use 'selected' if your page's DOCTYPE is not XHTML or if you do not care about your code being XHTML-compliant:

<option value="#contacts.ContactID#" <cfif contacts.contactID EQ SomeValriable>selected</cfif>>...</option>

Azadi
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now