Quantcast
Viewing all articles
Browse latest Browse all 21760

Re: Select dropdown list show last record

<option value="#spList.MyID#" <cfif (isDefined("spList.MyID") AND spList.MyID EQ spList.MyID)>selected="selected"</cfif>>#spList.MyNUMBER# - #spList.<MyNAME#</option>

 

There's two fundamental things wrong here.

 

Firstly you refer to #spList.MyID#.  Then you say isDefined("spList.MyID").  It must be defined, otherwise the code would error when you referred to it the first time.

 

Secondly, you then say "spList.MyID EQ spList.MyID"  - uh, that's like saying if A EQ A - it's always true.  I'm assuming you have some other value set somewhere for the ID of one particular row in your query you want to have selected.  That's what you should use instead.

 

This should end up looking something more like:

 

<option value="#spList.MyID#" <cfif isDefined("someOtherID") AND spList.MyID EQ someOtherID>selected="selected"</cfif>>#spList.MyNUMBER# - #spList.<MyNAME#</option>

 

Although a further improvement - isDefined() is generally considered less than optimal these days, and it's better to use structKeyExists() instead.  e.g.

 

<option value="#spList.MyID#" <cfif structKeyExists(variables, "someOtherID") AND spList.MyID EQ someOtherID>selected="selected"</cfif>>#spList.MyNUMBER# - #spList.<MyNAME#</option>


Viewing all articles
Browse latest Browse all 21760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>