Solved

Populate <cfselect> with query data

Posted on 2015-02-11
3
136 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
[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
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 29

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

739 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