1

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>" );
            }
3
  • In the section that doesn't work, you terminate the cell with </td> immediately on the first line. Was that intended? Commented Apr 22, 2015 at 14:29
  • 1
    cfselect is 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 use cfselect at 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 getting cfselect to do what you want. Commented Apr 22, 2015 at 14:34
  • Please check the thing which I tried, It worked with select and CFLOOP inside JavaScript. Commented Apr 23, 2015 at 7:03

1 Answer 1

2

You can't write CFML to the screen and hope that it'll magically execute! THat's your problem.

This article "The CFML request/response process" explains it thoroughly, but - bottom line - CFML needs to be compiled before it's executed, and that needs to be done by the CFML server, not the client browser.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Adam, I edit my question. Added which I tried in JavaScript part. Please check.
This doesn't change the fact you can't output CFML code and expect it to run. Did you read the link I posted? You simply cannot do what you're trying to do here. CFML runs on the CFML server, JS runs on the client browser. You are trying to run CFML on the client. You can't. Simple as that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.