Solved

Auto Select Cfselect tag

Posted on 2009-05-16
3
344 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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