title: Need to turn javascript (ajax) vote script into reusable (dynamic) script so it can be used over and over
body: <p>Need to turn javascript (ajax) vote script into reusable (dynamic) script so it can be used over and over.</p>
  
  <p>I have some ajax that works great, but I have to reproduce it and add unique identifiers [where you see 9 in the code are the unique identifiers that I have to change] for every question added that needs a vote. Need to make it dynamic so it will reproduce itself or can be reused with onclick identifiers no matter how many questions are in the database.</p>
  
  <p>Tried to put the javascript in-between &lt;CFOUTPUT QUERY="GetVotes"&gt; &lt;/CFOUTPUT&gt; tags so I could change the 9 to what ever the #GetVoteID# is for the vote question and dynamically reproduce the script as the questions are reproduce from the CFOUTPUT. But that didn’t work as the #GetVoteID# in the javascript caused the script not to work and I don’t know how to make the script reusable with onclick identifiers. </p>
  
  <p>I see the thumbs up and down vote questions on lots of sites and the questions are dynamically reproduce though a database output, what are they doing to reuse there ajax?</p>
  
  <p>I know onclick identifiers are the way to go, so any help on how I can convert my script, CFC’s, and whatever else so that it can handle 10, 20 or 1000 questions that need a vote.</p>
  
  <p>Below is my code (The links, cfajaxproxy, CFC’s, and javascript)</p>
  
  <p><strong>Yes / No links</strong><br>
      <code>&lt;CFOUTPUT QUERY="GetVoteList"&gt;<br>
              &lt;A HREF="javascript:()" onclick="GetVoteYes9(#GetVoteID#);"&gt;Yes&lt;/A&gt;<br>
              &lt;A HREF="javascript:()" onclick="GetVoteNo9(#GetVoteID#);"&gt;No&lt;/A&gt;<br>
      &lt;/CFOUTPUT&gt;</code></p>
  
  <p><strong>Style for ajax</strong><br>
      <code>&lt;STYLE&gt;<br>
          GetVoteDescription9{visibility : visible}<br>
      &lt;/STYLE&gt;</code>  </p>
  
  <p><strong>cfajaxproxy</strong><br>
  <code>&lt;cfajaxproxy cfc="CFC/GetVoteYes9" jsclassname="YesVote9CFC"&gt;<br>
  &lt;cfajaxproxy cfc="CFC/GetVoteNo9" jsclassname="NoVote9CFC"&gt;</code> </p>
  
  <p><strong>YesVoteCFC</strong>  </p>
  
  <pre><code>&lt;cfcomponent&gt;
      &lt;cffunction name="NewCount9" access="remote"&gt;
          &lt;CFQUERY NAME="YesCount9CK" DATASOURCE="MyDSN"&gt;
              SELECT  *
              FROM    GetVote
              WHERE   GetVoteID = &lt;cfqueryparam value="9" cfsqltype="CF_SQL_INTEGER"&gt;
          &lt;/CFQUERY&gt;
          &lt;CFSET NewCount9=#YesCount9CK.YesCount#+1&gt;
          &lt;CFQUERY NAME="UpdateYesCount" DATASOURCE="MyDSN"&gt;
              UPDATE  GetVote
              SET     YesCount = &lt;cfqueryparam value="#NewCount9#" cfsqltype="CF_SQL_INTEGER"&gt;
              WHERE   GetVoteID = &lt;cfqueryparam value="9" cfsqltype="CF_SQL_INTEGER"&gt;
          &lt;/CFQUERY&gt; 
          &lt;cfreturn NewCount9&gt;
      &lt;/cffunction&gt;
  &lt;/cfcomponent&gt;
  </code></pre>
  
  <p><strong>NoVoteCFC</strong>  </p>
  
  <pre><code>&lt;cfcomponent&gt;
      &lt;cffunction name="NewCount9" access="remote"&gt;  
          &lt;CFQUERY NAME="NoCount9CK" DATASOURCE="MyDSN"&gt;  
              SELECT  *  
              FROM    GetVote   
              WHERE   GetVoteID = &lt;cfqueryparam value="9" cfsqltype="CF_SQL_INTEGER"&gt;  
          &lt;/CFQUERY&gt;  
          &lt;CFSET NewCount9=#NoCount9CK.NoCount#+1&gt;  
          &lt;CFQUERY NAME="UpdateNoCount" DATASOURCE="MyDSN"&gt;  
              UPDATE  GetVote  
              SET     NoCount = &lt;cfqueryparam value="#NewCount9#" cfsqltype="CF_SQL_INTEGER"&gt;  
              WHERE   GetVoteID = &lt;cfqueryparam value="9" cfsqltype="CF_SQL_INTEGER"&gt;  
          &lt;/CFQUERY&gt;   
          &lt;cfreturn NewCount9&gt;  
      &lt;/cffunction&gt; 
  &lt;/cfcomponent&gt;
  </code></pre>
  
  <p><strong>ajax script</strong>  </p>
  
  <pre><code>&lt;SCRIPT TYPE="text/javascript"&gt;
      function GetVoteNo9()  
      {   
          var GetVoteNo9 = document.getElementById("GetVoteNo9"); 
          var cfc = new NoCFC9();  
              cfc.setCallbackHandler(getDataResultNo9);  
              cfc.NewCount9(true);  
          var GetVoteDescription9 = document.getElementById("GetVoteDescription9").style.display='none'; 
          var content = document.getElementById('YesResponse9').innerHTML='';
          var content = document.getElementById('NoResponse9').innerHTML='You voted No';
      }  
      function getDataResultNo9(NoResult9)  
      {  
          var content = document.getElementById('NoCount9').innerHTML=NoResult;
      } 
  
      function GetVoteYes9()  
      {  
          var GetVoteYes9 = document.getElementById("GetVoteYes9"); 
          var cfc = new YesCFC9();  
              cfc.setCallbackHandler(getDataResultYes9);  
              cfc.NewCount9(true);  
          var GetVoteDescription9 = document.getElementById("GetVoteDescription9").style.display='none'; 
          var content = document.getElementById('YesResponse9').innerHTML='You voted Yes';
          var content = document.getElementById('NoResponse9').innerHTML='';
      }  
      function getDataResultYes9(YesResult9)  
      {  
          var content = document.getElementById('YesCount9').innerHTML=YesResult;
      }
  &lt;/SCRIPT&gt;  
  </code></pre>