Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

single/multiple value retrieval

Status
Not open for further replies.

LAdProg2005

Programmer
Feb 20, 2006
56
US
Hi all,

I am creating a list box where i can select multiple values
but no matter what i do i only get back one value. I can select two but it ends up returning the first value selected. what may i be doing wrong? Thanks,

Code:
<select id="selName" multiple="multiple" >
<cfquery name="getName" DBtype="Query">
   SELECT DISTINCT name
   FROM Employee
</cfquery> 
<option value="all" <cfif selName eq "all">selected="selected"</cfif> >ALL</option>
<cfoutput query="getName">
  <option value = "#name#" <cfif selName eq name>selected="selected"</cfif> >
   #name#
  </option>
</cfoutput>
</select>
 
<cfif selName eq name>selected="selected"</cfif>

If only one item is selected, that suggests your CFIF condition is returning false. The quickest way to figure out why, is to perform some debugging.

Copy the cfoutput loop and display the two values you are comparing on the screen. Once you can see the values, you will probably know why they are not equal.

Code:
Debugging code:<br>
<cfoutput query="getName">
  selName=#selName# name=#name# <br>
</cfoutput>

----------------------------------
 
Right, I realized it is using only one value for which it works but I do not know programmatically how to account for more than one values...

Thanks
 
If you think of #selName# as a "list" of values, you can use list functions to determine if #name# is one of the list elements.


Code:
<cfif listFindNoCase(selName, name) GT 0>
   ... #name# was found in the list ....
</cfif>

... or the short-hand version ...
<cfif listFindNoCase(selName, name)>
   ... #name# was found in the list ....
</cfif>

BTW, it is a good practice to scope your variables. It avoids unintentional scope conflicts.

Use: #form.selName# or #url.selName#
Instead of: #selName#

----------------------------------
 
I gave that a try as well listFindNoCase and listFind

<option value = "#name#" <listFindNoCase(selName, name)>selected="selected"</cfif> >
#name#
</option>

but it still returns the 1st in the list
ie. if names list: (bp ap sp tp)
and if i select bp & sp, it returns bp only when printing the variable.

to get it i use:
<cfif isDefined(url.selName)>
<cfset selNameN = url.selName>
</cfif>
<cfoutput>selNameN</cfoutput>

thanks
 
Dump the entire URL scope at the top of your action page. What is the value of url.selName?

<!--- dump both scopes --->
<cfdump var="#url#">
<cfdump var="#form#">

<cfset selNameN = url.selName>

You do not really need to assign url.selName to another variable. You can just use #url.selName#.

<cfif isDefined(url.selName)>

Is that psuedo code? If not, the IsDefined() function requires quotes around the variable _name_.

ie Use
isDefined("url.selName")
... not
isDefined(url.selName)



----------------------------------
 
Tried that as well :)

if i select bp & sp, it returns bp only when printing the variable
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top