Link to home
Start Free TrialLog in
Avatar of hoetom
hoetom

asked on

how do I pass a coldfusion variable to a cfselect bind attribute

I have a cfselect tag like the following:

<cfselect name="patientfind"
    bind="cfc:subjects.subject_select({subject_name@keydown},39,1)"
      value="entityid"
    display="fullname"
      size="5"
      width="200"      />

I need to be able to replace the two last arguments (the 39 and 1) with coldfusion variables defined in the template that houses the cfselect statement. I have tried several different methods, from string concatenation to using ## around the variables names like this:
 
bind="cfc:subjects.subject_select({subject_name@keydown},#project_id#,"user_id#1)"

But none of these work. They all cause different javascript errors.

I figure that I am just missing something simple.

Your advice is greatly appreciated.

Tom
<cfselect name="patientfind"
    bind="cfc:subjects.subject_select({subject_name@keydown},39,1)"
	value="entityid"
    display="fullname" 
	size="5"
	width="200"	/>
 
<cfselect name="patientfind"
    bind="cfc:subjects.subject_select({subject_name@keydown},#project_id#,#user_id#)"
	value="entityid"
    display="fullname" 
	size="5"
	width="200"	/>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of erikTsomik
erikTsomik
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of _agx_
You could always put the values in hidden fields,

<cfinput type="hidden" name="project_id" value="#project_id#">
<cfinput type="hidden" name="user_id" value="#user_id#">

... then use the the hidden fields as the last two values in the bind.
... Though using variables works fine for me

<cfselect..   cfc:mycfc.mymethod(#project_id#,#user_id#)">
yes, just passing cf vars works fine. what you need to check is if your cfc function accepts them - does it have <cfargument> defined for each? are they required or not? are you passing them to the function in correct order?

also keep in mind that you can't pass a comma-delimited list as cf variable to your function via binding. you need to change list delimiters to something other than a comma.

Azadi
Avatar of hoetom
hoetom

ASKER

Thank you all for your advice.

I had tried wrapping the variable names in #, but it hadn't worked. I was getting by Firebug that I had an undefined variable. I played around with what I was passing and determined that I only got that error if the value of the variable that I was passing was a string.

In this case, I had to wrap the variable in a pair of single quotes, along with the #, or like this:

bind="cfc:subjects.subject_select({subject_name@keydown},#project_id#,'#user_id#')"

It is a long story on why my user_id is a string...

Thanks for your help.
Tom
> I had to wrap the variable in a pair of single quotes

Well, if it is either a string value or type,  then yes. Strings pretty much always need to be quoted ;-)