Solved

Auto Select Cfselect tag

Posted on 2009-05-16
3
311 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
website file permissions 4 65
X-Frame-Options - click-jacking 7 56
Asp.net plan security, reliable, stable 2 110
Apache SSL and mod_rewrite not working 8 123
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 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

17 Experts available now in Live!

Get 1:1 Help Now