Search code examples
javascriptjqueryselectcoldfusioncfquery

Unable to access JavaScript variables in ColdFusion tags in script


I was trying to take the selected value from the select tag and pass it to cold fusion tags in jquery as follows.

select tag code:

<select id="selectco">
<cfoutput query="colist">
<option value="#cid#">#coname#</option>
</cfoutput>
</select>

jQuery code:

$(document).ready(function() 
{
    $("#selectco").change(function() 
    {
        var e=document.getElementById("selectco");
        var opt=e.options[e.selectedIndex].value;
         $("#selectst").html("<cfquery name='stlist' datasource='tasks'>
select * from state where cid='"+opt+"'
</cfquery><select id='selectct'><cfoutput query='stlist'><option>#stname#</option></cfoutput>");
    });
});

I was able to take the value to opt variable.But am unable to pass the value to the cfquery tag. Please help me.


Solution

  • CFML is parsed on the ColdFusion server; Javascript runs on the client browser. The two never "exist" in the same space.

    I recommend you read my blog article describing how CF participates in a request.

    What you need to do is to read up on data binding in ColdFusion (or in general), which is fairly well documented, so there's little point in replicating it here.