Skip to main content
August 27, 2007
Question

cfselect selected with bind

  • August 27, 2007
  • 5 replies
  • 2125 views
I have a cfselect that is being populated by cfc remotely, how do I have an option selected by default? Using the selected attribute does not work, nor does hardcoding an option.

Is there a way to define which option should be selected in the cfc results?

Code:
<cfselect name="propertyType" bind="cfc:/com/form.getPropertyTypes()" bindonload="true" ></cfselect>
This topic has been closed for replies.

5 replies

Inspiring
September 19, 2007
kyle969 wrote:
> The first value in the list is selected by default if none are marked as
> 'selected'. As I said, this is hokey and there has to be a better way.
>
> I have run into a situation where I have a multiple select box and I need
> multiple selections automatically selected.
>
> Any ideas?
>
> Anyone?
>

follow-up:

anyone still looking for solution to this:

good old fellas ray camden and tod sharp have solved it
here:
http://www.coldfusionjedi.com/index.cfm/2007/8/7/Selecting-default-items-using-ColdFusion-8s-AJAX-Controls

and here:
http://cfsilence.com/blog/client/index.cfm/2007/8/7/Selecting-Multiple-Default-Items-With-ColdFusion-8-Ajax-Controls

--

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
Inspiring
August 29, 2007
kyle969 wrote:
> I have run into a situation where I have a multiple select box and I need
> multiple selections automatically selected.
>
> Any ideas?

i think binding will not let you do this...

but then again i do not think your multiple select will be the second
select in a chain of related selects, right? it is probably the first
(or the only) select box?

if so, then you could return a comma-delimited list of values (the ones
to be pre-selected) from your cfc, and then have a regular select
element populated with regular option elements which are inside a cfloop
to check if the value of current option element is in the list passed
form cfc, and set selected=selected if it is...

--

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
August 28, 2007
The first value in the list is selected by default if none are marked as 'selected'. As I said, this is hokey and there has to be a better way.

I have run into a situation where I have a multiple select box and I need multiple selections automatically selected.

Any ideas?

Anyone?
Inspiring
August 28, 2007
good job!
but is it actually selected in the cfselect?
i mean, if it is just the first element in the select box, it is not
necessarily 'selected', as in: its value is the value of the
form.selectbox... or is it?

but even if not, i suppose you could always employ a little javascript
to make the first element in select box 'selected' on page load....
--

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
August 27, 2007
I found a hokey solution by passing the value I want selected to the cfc in the bind and doing an arrayInsertAt to position 1 of the array.

if(len(pTypeSelected)){
arrayInsertAt(aPropertyTypes,1,arrayNew(1));
aPropertyTypes[1][1] = pTypeSelected;
aPropertyTypes[1][2] = pTypeSelected;
}