If the value isn't changing after the page is rendered you may be able to use 
document.write java script to write the variable to a CF variable that you can 
pass to the CFC.  I've done that before and it works fine, so long as the 
variable doesn't change after the page is rendered.

Robert Harrison 
Director of Interactive Services

Austin & Williams
Advertising I Branding I Digital I Direct  
125 Kennedy Drive,  Suite 100   I  Hauppauge, NY 11788
T 631.231.6600 X 119   F 631.434.7022   
http://www.austin-williams.com

Blog:      http://www.austin-williams.com/blog
Twitter:  http://www.twitter.com/austin_williams 


-----Original Message-----
From: Rick Faircloth [mailto:[email protected]] 
Sent: Wednesday, January 15, 2014 3:57 PM
To: cf-talk
Subject: How do I pass this jQuery variable as arguments to a cfc method?


Hi, all...

I've approached this problem from every direction I can think of and with 
reference to many, many websites, but I still can put together an answer.

I have this HTML in a form:

  <cfoutput query = "qGetSpecials">

  <div class="special_title_container">
  <span class="title_checkbox_span">
  <input id="special_id_#special_id#" class="special_title_checkbox"
value="#special_title#" type="checkbox" name="special_title">
  </span>
  <span class="special_title_span">#special_title#</span>
  </div>

  </cfoutput>

Which is output into this:

<input id="special_id_26" class="special_title_checkbox" value="First Special" 
type="checkbox" name="special_title"> <input id="special_id_27" 
class="special_title_checkbox" value="Second Special" type="checkbox" 
name="special_title"> <input id="special_id_28" class="special_title_checkbox" 
value="Third Special" type="checkbox" name="special_title">

This jQuery processing the inputs:

$(document).ready(function() {

  $('#newsletter_preview_button').click(function() {

  var specialTitleID = $('.special_title_checkbox:checked');

  $('.special_title_checkbox:checked').each(function(index,value) {

  var specialTitleID = $(this).attr('id').split('_').pop();
  var specialTitleID = 'specialTitle_'+specialTitleID;

  alert(specialTitleID); <--- [ this alerts the three input values, 26, 27, 28, 
individually when form is submitted ]

  });

  values     =  {   emailNewsletterGreeting:     emailNewsletterGreeting,
  specialTitleID:                     specialTitleID    }

          (Followed by AJAX code...)

And this cfc method:

  <cffunction     name               =     "mProcessEmailNewsletterForm"
  displayName    =  "mProcessEmailNewsletterForm"
hint                  =  "Processes Email Newsletter Form"
  output              =  "true"
  access             =  "remote"
  returnType        =  "struct" >

  <cfargument name = "emailNewsletterGreeting"     type = "string"
  required = "no" />
  <cfargument name = "specialTitleID"                     type =
"string"  required
= "no" />

  <cfset emailNewsletterStruct = structNew() />

  <cfset emailNewsletterStruct.email_newsletter_greeting     =
'#arguments.email_newsletter_greeting#'
/>
  <cfset emailNewsletterStruct.specialTitleID                       =
'#arguments.specialTitleID#'
/>

<cfreturn emailNewsletterStruct />

 </cffunction>

But, the cffunction above doesn't know what to do with the value, 
"specialTitleID", when it's received.
Or, rather, I don't know how to change it in the jQuery code or the cffunction 
code so that each specialTitleID can be separted into individual cfarguments.

I've tried specifying cfargument name="specialTitleID" as type="array", 
type="list", type="string", but I get a JS error in Firebug no matter what I 
try. I'm sure it's simple, I just haven't handled a multi-valued variable going 
via AJAX to a cfc method before. (or that I remember...).

Suggestions, anyone?

Thanks,

Rick

--
--------------------------------------------------------------------------------------------------------------------------------------------------
"Ninety percent of the politicians give the other ten percent a bad 
reputation."  Henry Kissinger




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:357431
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to