Solved

CFSelect: Getting 'bind' to work with selected values

Posted on 2009-04-06
6
687 Views
Last Modified: 2012-05-06
Hey Guys,

I've got a couple cfselects i'm binding.  Everything is working great, except there really isn't any out of the box solution to preselect the values if you are, for example, using the form to edit records.  I found a few articles on some workarounds and this one seemed to work for others... http://www.stevenksavage.com/content/500/3.en.cfm

My problem is I'm still a CF n00b and I can't figure out how to implement this fix.  So I'm hoping someone can point me in the right direction with this.

Here is what I have for code...  How could I implement the fix to the preselect values?
<!---------------------------Here are my cfselects -------------------------------->

<cfselect name="sale_buyer_id" id="sale_buyer_id" size="1" bind="cfc:lots.addWindow.getSaleBuyers4cfselect()" bindonload="true" display="sale_buyer_Name" value="sale_buyer_id" />
 

<cfselect name="sale_buyer_yard_id" id="sale_buyer_yard_id" bind="cfc:lots.addWindow.getSaleBuyerYards4cfselect({sale_buyer_id})" bindonload="false" display="sale_buyer_yard" value="sale_buyer_yard_id" />
 
 

<!---------------------------Here are my functions --------------------------------->

<cfcomponent displayname="populate">
 

<!--- Sale Buyers CFC to fill the cfselect query --->

<cffunction name="getSaleBuyers4cfselect" access="remote" returntype="query" output="false">

<cfset var qGetSaleBuyers="">
 

<cfquery name="qGetSaleBuyers" datasource="#request.dsn#">

SELECT sale_buyer_id, sale_buyer_name

FROM sale_buyer

ORDER BY sale_buyer_name

</cfquery>
 

<cfreturn qGetSaleBuyers />

</cffunction>
 

<!--- Sale Buyer Yards CFC to fill the cfselect query --->

<cffunction name="getSaleBuyerYards4cfselect" access="remote" returntype="query" output="false">

<cfargument name="sbid" required="no" default="0">

<cfset var qGetSaleBuyerYards="">
 

<cfquery name="qGetSaleBuyerYards" datasource="#request.dsn#">

SELECT sale_buyer_yard_id, sale_buyer_yard

FROM sale_buyer_yard

<cfif arguments.sbid gt 0>

WHERE sale_buyer_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.sbid#">

</cfif>

ORDER BY sale_buyer_yard

</cfquery>
 

<cfreturn qGetSaleBuyerYards />
 

</cffunction>
 

</cfcomponent>

Open in new window

0
Comment
Question by:MFredin
  • 3
  • 2
6 Comments
 
LVL 19

Expert Comment

by:erikTsomik
ID: 24081489
you need to include selected options

0
 

Author Comment

by:MFredin
ID: 24081572
erikTsomik,

Not clear on what you mean by selected options.  You mean the values I want to be selected?
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24083725
"selected" attribute does NOT work in cfselects with bindings.
here's a very good solution using a bit of js and <cfajaxproxy>:
http://www.coldfusionjedi.com/index.cfm/2007/8/7/Selecting-default-items-using-ColdFusion-8s-AJAX-Controls

steven's solution (the link you posted) looks interesting, but i have not yet been able to make it work...

Azadi
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:MFredin
ID: 24087759
Thanks Azadi,

The solution you linked to works for the first select box, but I can't seem to get it working on the second select box.  
<!--- Pre Select the Sale_Buyer_Id form element --->

<cfajaxproxy bind="javascript:test({sale_buyer_id},2)">

<script>

var imdone = false;

function test(x,val) {

if(!imdone) {

var dd = document.getElementById('sale_buyer_id');

for(var i = 0; i < dd.length; i++){

if(dd.options[i].value == val){

dd.selectedIndex = i;
 

}

}

imdone = true;

}

}

</script>
 

<!--- Pre Select the Sale_Buyer_Yard_Id form element --->

<cfajaxproxy bind="javascript:test2({sale_buyer_yard_id},3)">

<script>

var imdone = false;

function test2(x,val) {

if(!imdone) {

var dd = document.getElementById('sale_buyer_yard_id');

for(var i = 0; i < dd.length; i++){

if(dd.options[i].value == val){

dd.selectedIndex = i;
 

}

}

imdone = true;

}

}

</script>

Open in new window

0
 
LVL 27

Accepted Solution

by:
azadisaryev earned 500 total points
ID: 24094027
you need a different js variable to control the second cfselect. right now you have imdone js variable in both functions - rename it to something else in the second function.

Azadi
<cfajaxproxy bind="javascript:test({sale_buyer_id},2)"><!--- for Sale_Buyer_Id --->

<cfajaxproxy bind="javascript:test2({sale_buyer_yard_id},3)"><!--- for Sale_Buyer_Yard_Id --->

<script type="text/javascript">

var imdone = false; // var for Sale_Buyer_Id

var imdone2 = false; // var for Sale_Buyer_Yard_Id

function test(x,val) { // function for Sale_Buyer_Id

 if(!imdone) {

  var dd = document.getElementById('sale_buyer_id');

  for(var i = 0; i < dd.length; i++){

   if(dd.options[i].value == val){

    dd.selectedIndex = i;

   }

  }

  imdone = true;

 }

}

function test2(x,val) { // function for Sale_Buyer_Yard_Id

 if(!imdone2) {

  var dd = document.getElementById('sale_buyer_yard_id');

  for(var i = 0; i < dd.length; i++){

   if(dd.options[i].value == val){

    dd.selectedIndex = i;

   }

  }

  imdone2 = true;

 }

}

</script>

Open in new window

0
 

Author Comment

by:MFredin
ID: 24096637
Ah yes, makes sense!  Thanks!!
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

Title # Comments Views Activity
How to access an read a file outside of the web root. 5 32
Upgrading Internet Information Server 12 100
cfspreadsheet 15 85
Browser back button refreshing coldfusion iframe 6 72
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

23 Experts available now in Live!

Get 1:1 Help Now