When I run CFSELECT normally it runs perfectly, but when I add inside javascript it gives error.
The normal one It works.
<tr id='selectionDropdown'>
<td >Non-Keyword Traffic:</td>
<td>
<cfif Session.ID eq Session.userID>
<cfselect name="nonkeyword" multiple="true" query="GetCodes" display="Code" value="Code" selected=#Form.nonkeyword# >
</cfselect>
</cfif>
</td>
</tr>
It doesn't work
//The non keyword and all are checked
<td id='selectionDropdown'></td>
<cfoutput>
function ShowDropdown(){
if($('##nonKeyword').is(':checked') && !$('##all').is(':checked'))
{
$( "##selectionDropdown" ).empty();
$( "##selectionDropdown" ).append( "<td>Non-Keyword Traffic:</td><td><cfif Session.ID eq Session.userID><cfselect name='nonkeyword' multiple='true' query='GetCodes' display='Code' value='Code' selected='#Form.nonkeyword#' ></cfselect></cfif></td>" );
}
}
</cfoutput>
In browser I get error.
<td id='selectionDropdown'>Context validation error for tag cfselect.<td>
As I got some comments and answers. I am editing which I tried earlier not with CFSELECT.
When It can execute this one, why not with CFSELECT
if($('##nonKeyword').is(':checked') && !$('##all').is(':checked'))
{
$( "##selectionDropdown" ).empty();
$( "##selectionDropdown" ).append( "<td>Non-Keyword Traffic:</td><td><cfif Session.ID eq Session.userID><select name='nonkeyword' multiple='true' selected='#Form.nonkeyword#' ><cfloop query='GetCodes'><option value='#code#'>#code#</cfloop></select></cfif></td>" );
}
</td>immediately on the first line. Was that intended?cfselectis a ColdFusion tag which is interpreted on the server and converted to HTML and JavaScript which is then sent to your browser. You can't just mix it in with jQuery. The best thing to do is to not usecfselectat all but try and do it in jQuery or look at one of the many jQuery plugins. Probably worth asking a new question saying what you want to achieve rather than gettingcfselectto do what you want.