You can't bind with cfselect tags. However, you can use onChange and ActionScript to do it quite easily:
<cfselect name="state" required="true"
label="State"
message="Please select your state."
onChange="state_bi.selectedIndex=state.selectedIndex">
label="State"
message="Please select your state."
onChange="state_bi.selectedIndex=state.selectedIndex">


Comment 1 written by Karolis R. on 12 February 2005, at 2:39 PM
Comment 2 written by Raymond Camden on 12 February 2005, at 9:06 PM
Comment 3 written by Karolis R. on 13 February 2005, at 10:38 AM
If I was to populate the CFSELECT from a query, say there is thirty people in the list. The list is continually updated, people get added and deleted. ID associated with people names will NOT match INDEX value which always goes from 0 to RECORDCOUNT - 1. So if my grid would say USERID = 209, this code would look for selectedIndex value!!! But there is only 30 people in the list, so...
I think people at Macromedia released CF7 as a nice BETA version, since so many obvious functionalities, implied by their own design, are missing.
IF SOMEONE CAN FIGURE IT OUT, PLEASE POST IT, IT WOULD BE GREATLY APPRECEATED!!!
Comment 4 written by Raymond Camden on 13 February 2005, at 4:48 PM
this.options[selectedIndex].value
This is inside an onChange for the select so obviously THIS refers to the select box itself.
Comment 5 written by Karolis R. on 13 February 2005, at 5:05 PM
"this.options[selectedIndex].value" gives you selected value of <SELECT> instance, you cannot use it to change selection!!!
Comment 6 written by Raymond Camden on 13 February 2005, at 5:11 PM
ccyear.selectedIndex=4;
Obviously real code will be a bit more complex, but the important part is on the left side of the equation above.
Comment 7 written by Karolis R. on 13 February 2005, at 5:14 PM
read my 10:38AM post.
Comment 8 written by Raymond Camden on 13 February 2005, at 6:14 PM
Comment 9 written by Bill King on 10 March 2005, at 2:10 PM
I am using an invisible field to work between my select box and my grid. Then when the gridrow is selected my hidden field value is updated. That works with bind.
Then when I change selections from my select box the onClick changes the hidden field therefore updating the grid.
Problem is when I select a grid item I cannot match the id in my hidden textbox to the VALUE. I tried adding this to the onChange of the text box:
for (i=0; i<clientListSelect.length; i++)
{if (Client_id.text == clientListSelect.getItemAt[i].data) clientListSelect.selectedIndex = i}
Can't get any response from the browser. Thoughts?
Comment 10 written by Bill King on 10 March 2005, at 3:39 PM
I am using an invisible field to work between my select box and my grid. Then when the gridrow is selected my hidden field value is updated. That works with bind.
Then when I change selections from my select box the onClick changes the hidden field therefore updating the grid.
Problem is when I select a grid item I cannot match the id in my hidden textbox to the VALUE. I tried adding this to the onChange of the text box:
for (i=0; i<clientListSelect.length; i++)
{if (Client_id.text == clientListSelect.getItemAt[i].data) clientListSelect.selectedIndex = i}
Can't get any response from the browser. Thoughts?
Comment 11 written by Jeff Bouley on 22 September 2005, at 5:27 PM
I'm getting errors with your recommendation of "this.options[selectedIndex].value" in onChange, error states no property with the name 'options'. I too would like to retrieve value and text from a select box that has size. Data is great, fo r retrieving value and not text, but text seems to only work with selectedItem when there is no size to the select. Any info. appreciated.
Comment 12 written by Jeff Bouley on 23 September 2005, at 5:45 AM
Comment 13 written by Raymond Camden on 23 September 2005, at 6:44 AM
Comment 14 written by Thomary on 12 December 2005, at 1:06 PM
<cfgrid name="gridname" query="getArtists" height="155" width="755" rowheaders="false"
onchange="for(var i:Number = 0; i<cfselect.length; i++) {if(cfselect.getItemAt([i]).data==gridname.selectedItem.columnname)cfselect.selectedIndex=i}
for(var i:Number = 0; i<cfselect2.length; i++) {if(cfselect2.getItemAt([i]).data==gridname.selectedItem.columnname2)cfselect2.selectedIndex=i}">
My problem: These cfselect fields are not required. So in the database sometimes there is data and sometimes it's null.
When the grid selection is made - and there is data the cfselects are filled in. Great!.
But the next grid selection - there is no data the cfselects keep the last data (until another grid change with data)
I need to clear the cfselects at the begining of the actionscript and then pick up the grid selection. Any help would be great!!!
Comment 15 written by corey on 23 January 2006, at 4:20 PM
not sure if your question was answered yet, but you can reset the select value everytime during the onChange so the previous value is not there when an empty value is selected. Just set the index value to 0 (assuming you have an option like "Select" with an empty value) in the begining of your onChange statment:
old way:
onchange="for(var i:Number = 0; i<cfselect.length; i++) {if(cfselect.getItemAt([i]).data==gridname.selectedItem.columnname)cfselect.selectedIndex=i}
for(var i:Number = 0; i<cfselect2.length; i++) {if(cfselect2.getItemAt([i]).data==gridname.selectedItem.columnname2)cfselect2.selectedIndex=i}">
new way:
onchange="{cfselect.selectedIndex=0}{cfselect2.selectedIndex=0}for(var i:Number = 0; i<cfselect.length; i++) {if(cfselect.getItemAt([i]).data==gridname.selectedItem.columnname)cfselect.selectedIndex=i}
for(var i:Number = 0; i<cfselect2.length; i++) {if(cfselect2.getItemAt([i]).data==gridname.selectedItem.columnname2)cfselect2.selectedIndex=i}">
Comment 16 written by Thomary on 26 January 2006, at 3:20 PM
Entering data in every record was my work around (lucky I was only using sample data until I finish the form). Thanks very much!!
Comment 17 written by thomary on 1 September 2006, at 9:13 AM
So when someone selects Inventory tag number = 123456
I can then set the type, model, location from my inventory database.
I tried the code below but I keep getting undefined in the cfinput fields on select.
Cfquery datasource=”tableinv” name=”myinv”
SELECT tagnum, type, model, location
FROM myinvtable
/cfquery
cfsavecontent variable="autofillinv"
type.text = myselect.selectedItem.type;
selecttype.text = myselect.selectedItem.model;
selectitem.text = myselect.selectedItem.location;
/cfsavecontent
Cfform….
cfSelect query="myinv" name=”myselect” label="Inv Tag Num" onchange=”#autofillinv#” value="tagnum" display="tagno" queryPosition="below" width="185"
option value="" /option
/cfSelect
cfinput type="text" name="type" label="Type" size="12" /
cfinput type="text" name="model" label="Model"size="25"/
cfinput type="text" name="location" label="Location" size="40" /
/cfform
Is something like this possible?
Is there something else I should look into?
I’d appreciate any direction.
Comment 18 written by Raymond Camden on 1 September 2006, at 9:46 AM
Comment 19 written by thomary on 6 September 2006, at 8:42 AM
The code doesn't work for cfinputs.
Cfquery datasource=”tableinv” name=”myinv”
SELECT tagnum, type, model, location
FROM myinvtable
/cfquery
cfsavecontent variable="autofillinv"
type.text = myselect.selectedItem.type;
model.text = myselect.selectedItem.model;
location.text = myselect.selectedItem.location;
/cfsavecontent
Cfform….
cfSelect query="myinv" name=”myselect” label="Inv Tag Num" onchange=”#autofillinv#” value="tagnum" display="tagno" queryPosition="below" width="185"
option value="" /option
/cfSelect
cfinput type="text" name="type" label="Type" size="12" /
cfinput type="text" name="model" label="Model"size="25"/
cfinput type="text" name="location" label="Location" size="40" /
/cfform
Can this be used on cfinputs?
Comment 20 written by Rio on 9 October 2006, at 7:42 PM
I´m trying to put a simple cfselect into a cfform but getting confused. I´m very new to actionscript and cf.
My cfinputs work fine outputting in the cfgrid:
<cfinput type="DateField" name="DTLEAVE" label="ACTION DATE:"
bind="{companyGrid.dataProvider[companyGrid.selectedIndex]['DTLEAVE']}" onChange="companyGrid.dataProvider.editField(companyGrid.selectedIndex, 'DTLEAVE', DTLEAVE.text);">
The problem is here when I have tried to incorporate the comments in this thread and it doesn´t throw an error but doesn´t output the db entries as the cfinputs do. I am a bit out of my depth-please help!! Thanks:
<cfselect name="NEXTSTEP" label="Next"
onChange="NEXTSTEP.selectedIndex=NEXTSTEP.selectedIndex">
<option value="SEND FAX">SEND FAX</OPTION>
<option value="SEND EMAIL">SEND EMAIL</OPTION>
<option value="CALL AND EMAIL">CALL AND EMAIL</OPTION>
<option value="CALL">CALL</OPTION>
<option value="NO">NO</OPTION>
<option value="MEETING">MEETING</OPTION>
</cfselect>
Comment 21 written by aubry on 9 November 2006, at 10:47 AM
I'm trying to change the value of a cfselect when I click on my cfgrid
my cfselect options are from a query
Thanks for your help
Comment 22 written by ed on 10 November 2006, at 11:20 AM
To have more than one select binding to a cfgrid just add actionscript to the cfgrid. By trial and error I worked out that you do the following:
On the cfgrid(this uses three cfselects):
<cfgrid name="UsersGrid" format="Flash"
query="qNames" rowheaders="No"
onchange="for (var i:Number = 0; i<state.length; i++) {if
(state.getItemAt([i]).data == UsersGrid.selectedItem.state)
state.selectedIndex = i} for (var i:Number = 0; i<meetingtime.length; i++)
{if (meetingtime.getItemAt([i]).data == UsersGrid.selectedItem.meetingtime)
meetingtime.selectedIndex = i}
for (var i:Number = 0; i<dept.length; i++) {if (dept.getItemAt([i]).data ==
UsersGrid.selectedItem.dept) dept.selectedIndex = i}
for (var i:Number = 0; i<city.length; i++) {if (city.getItemAt([i]).data ==
UsersGrid.selectedItem.city) city.selectedIndex = i}">
On the cfselect:
<cfselect name="dept" width="200" size="1" label="Dept."
onchange="UsersGrid.dataProvider.editField(UsersGrid.selectedIndex, 'dept',
dept.selectedItem.data);">
<option value="None">None</OPTION>
<option value="Cundinamarca">Cundinamarca</OPTION>
<option value="Antioquia">Antioquia</OPTION>
<option value="Boyaca">Boyaca</OPTION>
<option value="Sucre">Sucre</OPTION>
<option value="Atlantico">Atlantico</OPTION>
</cfselect>
Explanation:
To add a new cfselect just add in the onchange between the "" the
following:
for (var i:Number = 0; i<state.length; i++) {if (state.getItemAt([i]).data
== UsersGrid.selectedItem.state) state.selectedIndex = i}
change the field in this example "state" to your field name.
Watch out for upper and lower case-actionscript is case sensitive although
cf isn´t. Try to have your field names all uppercase and put all of the references in upper case as well then you won´t get problems. good luck.
Comment 23 written by aubry on 10 November 2006, at 2:16 PM
-> http://www.asfusion.com/blog/entry/coldfusion-flas...
post n° 127 ;-)
Have a nice week !
&thanks again !
Comment 24 written by Ed on 14 November 2006, at 10:55 AM
<cfinput type="DateField" name="DTLEAVE" label="ACTION DATE:"
bind="{companyGrid.dataProvider[companyGrid.selectedIndex]['DTLEAVE']}" onChange="companyGrid.dataProvider.editField(companyGrid.selectedIndex, 'DTLEAVE', DTLEAVE.text);">
Comment 25 written by sharon212 on 30 November 2006, at 1:53 PM
How can I bind values from select box to display those into text box? Please help me out..
Here is my code:
<cfform name="form" METHOD="POST" action="Faccdte.cfm" skin ="#skin#" format="flash" width="900" height="300">
<cfformgroup type="horizontal" >
<cfselect name = "thisselect"
label = "AccNo"
required="yes"
width="170">
<cfloop query="getAccNo">
<option value = #getaccno.prdtyd#, #getaccno.accno#, #getaccno.acccud#, #getaccno.bookbal#,#getaccno.vdbbal# > #getaccno.ACCNO# </option>
</cfloop>
</cfselect>
</cfformgroup>
<cfinput type="text" name="prdtyd" width="200" label="Account Type" bind="{select.selectedItem.data}">
<cfinput type="text" name="Accno" width="200"...>
<cfinput type="text" name="Acccud" width="200"...>
<cfinput type="text" name="bookbal" width="200"...>
<cfinput type="text" name="vdbbal" width="200"...>
</cfform>
</cfoutput>
Comment 26 written by Howrad on 18 December 2007, at 4:17 PM
Comment 27 written by Thomary on 26 December 2007, at 8:47 AM
{thisselect.selectedItem.data}
Comment 28 written by Simon on 26 February 2008, at 8:00 AM
<cfselect name="status" size="1" id="status" label="Status" multiple="No" width="160" required="Yes" message="Please select the status" bind="{data.dataProvider[data.selectedIndex]['status']}" onChange="data.dataProvider.editField(data.selectedIndex, 'status', status.text)">
<option value = "">Select Status</option>
<option value = "Pending">Pending</option>
<option value = "Won">Won</option>
<option value = "Lost">Lost</option>
<option value = "Requoted">Requoted</option>
</cfselect>
whidch is the same technique I am using to bind my text fields to my cfgrid. However, when I select a row on the grid the cfselect does not show the value. The grid will change if I choose an option from the cfselect, but the cfselect just does not show the relevant value when i click on a row....any thoughts please?
Comment 29 written by thomary on 26 February 2008, at 8:08 AM
You must update the select field on the onChange of the Grid.
First set the select to null with:
{status.selectedIndex=0}
Then set the select with your data
for(var i:Number = 0; i<status.length; i++)
{if(status.getItemAt([i]).data==data.selectedItem.status)status.selectedIndex=i}
Comment 30 written by Simon on 26 February 2008, at 8:11 AM
so the two lines of code you specified, where do they reside in my code? sorry, just trying to get to grips with grids, and its my first time binding!
thanks again
Comment 31 written by thomary on 26 February 2008, at 8:17 AM
for(var i:Number = 0; i<status.length; i++)
{if(status.getItemAt([i]).data==data.selectedItem.status)status.selectedIndex=i}"
I got this off Ben Forta's blog a while back. It's great help for all of us.
Comment 32 written by Simon on 26 February 2008, at 8:24 AM
so my grid code:
<cfgrid name="data" height="300" query="agent" format="flash" onChange="{status.selectedIndex=0}
for(var i:Number = 0; i<status.length; i++)
{if(status.getItemAt([i]).data==data.selectedItem.status)status.selectedIndex=i}" >
my cfselect code:
<cfselect name="status" size="1" id="status" label="Status" multiple="No" width="160" onChange="data.dataProvider.editField(data.selectedIndex, 'status', status.text)">
<option value = "">Select Status</option>
<option value = "Pending">Pending</option>
<option value = "Won">Won</option>
<option value = "Lost">Lost</option>
<option value = "Requoted">Requoted</option>
</cfselect>
So at the moment, if I change the cfselect the relevant column in the grid changes. But, when I first click on the grid row, my text fields populate with the data, but the cfselect field just stays as "Select Status"
Sorry...
Comment 33 written by Simon on 27 February 2008, at 5:45 AM
[Add Comment] [Subscribe to Comments]