Solved

Populate <cfselect> with query data

Posted on 2015-02-11
3
123 Views
Last Modified: 2015-02-13
I am trying to populate my form with data returned from my query .... <cfinput> are populating just fine but <cfselect> i can not get to populate ... I'm using coldfusion 11 ... and to populate the <cfinput value =querydata.field... but that doesn't work for select ... I have a yes no and I want it to switch to the value returned (for example No then it should show no in case I wanted to update and change to yes ...  is there a simple way to do this
<cfform >
	

              </p>
   	      <label for="email">Email Address</label>
	     <cfinput type="text" name="email" message="Please enter an email address." value="#qEditRoles.email#" 
				validateat="onSubmit" validate="email" required="no" id="email" size="50" maxlength="50">
		</p>
		       	   <cfselect name="admin_priv_select" id="admin_priv"size="3">
		            <option value="1">Yes</option>
		            <option value="0">No</option>
		            </cfselect>
		       	  </p>
</cfform>

Open in new window

0
Comment
Question by:dolamitejenkins
3 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 40605408
You're not using any features of CFSELECT so might as well just use SELECT, but either way, you need to add a condition CFIF to determine which option should be selected like this..

What if the value is empty in the database (such as with a new record?)  YOu need to default it to one of the values or add a third option like this..

		       	   <select name="admin_priv_select" id="admin_priv"size="3">
		            <option value="" <cfif qEditRoles.admin_priv_select is "">selected</cfif>>-Choose-</option>
		            <option value="1" <cfif qEditRoles.admin_priv_select is "yes">selected</cfif>>Yes</option>
		            <option value="0" <cfif qEditRoles.admin_priv_select is "no">selected</cfif>>No</option>
		            </select>

Open in new window

0
 
LVL 28

Expert Comment

by:Pravin Asar
ID: 40606363
If your database permits only two values Yes or No,  then may be you do not use cfselect, use radio (which may default to "no".

But answering you question, you can populate cfselect with query. You can set the selected value too.

see example:

<cfset qData = QueryNew ("value,display","varChar,varchar" )/>
<cfset t = QueryAddRow(qData)/>
<cfset t = QuerySetCell(qData,"value","no")>
<cfset t = QuerySetCell(qData,"display","No")>
<cfset t = QueryAddRow(qData)/>
<cfset t = QuerySetCell(qData,"value","yes")>
<cfset t = QuerySetCell(qData,"display","Yes")>
<cfset user_is_admin = "no">

<cfform name="f1">
      <cfselect name="sel1" value="value" display="display" query="qData" selected="#user_is_admin#" queryPosition="below">
            <option value="">Select Option</option>
      </cfselect>
</cfform>
0
 

Author Closing Comment

by:dolamitejenkins
ID: 40608382
thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

896 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