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">
Archived Comments
There is one problem with this code! What if related values have two differen selectedIndex values? What I am trying to say this code does not bind database data directly!
My example was assuming both selects had the same data. Obviously you would modify for other situations - but the point is - that is the base code you can use to work with.
The only problem is, I nor many people I've talked to know a way that actionscript could be used to select by OPTION's VALUE="".
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!!!
Are you asking if is possible to get the VALUE attribute? If so - there is. You can get both the value and text of a particular OPTION item. So in your drop down, if VALUE was the primary key of the user and the TEXT was the username, you can access the value like so:
this.options[selectedIndex].value
This is inside an onChange for the select so obviously THIS refers to the select box itself.
What I am trying to do is to make changing CFGRID data change SELECTED VALUE in <SELECT>.
"this.options[selectedIndex].value" gives you selected value of <SELECT> instance, you cannot use it to change selection!!!
Eh? To change the selected index of a select box, let's say named ccyear, you can simply do this:
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.
What I meant was... How to change the selected value by NOT KNOWING selectedINDEX, only the actual value of the record.
read my 10:38AM post.
Oh - well use the code I described above to loop over all the items. Ie, loop from i=0 to the number of items in the drop down and check the foo.options[i].value property.
I am havnig trouble executing the loop statement. Here is what I have:
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?
I am havnig trouble executing the loop statement. Here is what I have:
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?
Ray,
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.
Got it... To access data in a flash cfselect, to get id information you'd use mySelect.selectedItem.data, but to get the display value you'd use mySelect.selectedItem.label.
So you are all good Jeff?
I've got two cfselects and this actionscript is on the onChange of the grid that works for me.
<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!!!
Thomary
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}">
Absolutely fantastic. You saved me again.
Entering data in every record was my work around (lucky I was only using sample data until I finish the form). Thanks very much!!
I'm trying to use a cfSelect to fill other cfinput fields. Inventory is too large to fill a grid. It takes too long to open the form.
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.
You set selecttype and selectitem - but I don't see them. I see type, model, and location.
I'm sorry, I was using the code from another area that works and just changed it to the new code I'm trying to get working. The code that works are all cfselects.
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?
Hi Ray and all,
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>
hello
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
Have a look at this this is for more than one select binding. Works the same as for one.
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.
Thanks a lot it works for me now but I've a second problem
-> http://www.asfusion.com/blo...
post n° 127 ;-)
Have a nice week !
&thanks again !
Instead of using an input meaning that users can change things how can I just output the value in a cfform? I imagine I am trying to do something that cfform flash format can´t do. What I want to do is output the value below and keep it binding to the grid. Any ideas or impossible? Thanks a lot
<cfinput type="DateField" name="DTLEAVE" label="ACTION DATE:"
bind="{companyGrid.dataProvider[companyGrid.selectedIndex]['DTLEAVE']}" onChange="companyGrid.dataProvider.editField(companyGrid.selectedIndex, 'DTLEAVE', DTLEAVE.text);">
Hi,
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>
Do you know if you still can not bind to cfselect in CF8?
I think if you use the name of the cfselect
{thisselect.selectedItem.data}
Hi, I am using
<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?
cfselects are different.
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}
Thanks for the prompt reply,
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
<cfgrid name="data" onChange="{status.selectedIndex=0}
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.
Thanks again, but it hasn't changed anything...?
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...
sorry, Am I not making any sense?