Skip to main content
Participant
March 6, 2014
Question

CFCLIENT JS code generation - tagname, classes, attributes

  • March 6, 2014
  • 1 reply
  • 522 views

Referring to the same code mentioned in my previous post:

<span class="test">

<cfclient>

          <cfset variable1 = 10>

          <cffunction name="test1">

                    <cfoutput>#variable1#</cfoutput>

                    <cfset variable1 = 20>

                    <cfoutput>#variable1#</cfoutput>

          </cffunction>

          <cfset test1()>

</cfclient>

</span>

The code that gets generated and executed will insert a DOM node into the page:

<span class="test">

<script type="text/javascript" src="/CFIDE/cfclient/cfclient_main.js"></script>

<script type="text/javascript" src="/CFIDE/cfclient/cffunctions.js"></script>

<meta name="viewport" content="width=device-width">

<script type="text/javascript">globalDivStruct=null;var _$test_func=function(){var self=this;var variables={};self.test1=function(){var localdivstruct=globalDivStruct;var __output_var="";localdivstruct.outputvar+=variable1;variable1=20;localdivstruct.outputvar+=variable1;return""};self.__init=function(){var localdivstruct=globalDivStruct;var __output_var="";var tmpVarArray={};variable1=10;test1();return""}};

function __startPage__$test(){document.write("\x3cdiv id\x3d'__cfclient_0'\x3e\x3c/div\x3e");window.ispgbuild=false;var clientDivStruct={divId:"__cfclient_0",outputvar:""};globalDivStruct=clientDivStruct;try{_$test=new _$test_func;_$test.__init()}catch(__eArg){if(__eArg!=="$$$cfclient_abort$$$")throw __eArg;}__$cf.__flush(clientDivStruct)}__startPage__$test();function test1(){return _$test.test1()};

</script><div id="__cfclient_0">1020</div>

</span>

Notice that it creates a div element and with id="___cfclient_0", can I specify the tag name that has to be generated? For example, if I want a span element or a list element then I should be able specify that. Also, one should be able to add classes to it, specify attributes (data-).

This topic has been closed for replies.

1 reply

Dave Ferguson
Participating Frequently
March 15, 2014

First, cfclient code should be at the top of the document.  It will not output into a span like you have here.  What I would do is either have your function return the data to the caller or have the function put the data into a specified html element.  Otherwise you will have no control as to the output of the data.

For example...

<cfclient>

          <cfset variable1 = 10>

          <cffunction name="test1">

                    <cfargument name="inVar" required="true">

                    document.getElementById('myDiv').html(inVar);

          </cffunction>

          <cfset variable1 = 10>

          <cfset test1(variable1)>

</cfclient>

<div id="myDiv"></div>

HTH,

--Dave