Erin Brewer wrote: [snip] > Is there no way to keep my current context when the ajax onComplete > function is triggered?
The easiest way is to just use a closure. > var NamedActionElement; > > function NamedActionHandler(theElement) > { > //set our global reference to the element so we can access it in later > functions > //since ajax calls take us to other functions and we can't seem to pass > it along > NamedActionElement = theElement; > > //skip setting up my vars for the ajax call > > //make the ajax call > var ajaxCall = new Ajax.Request( urlCall, > {method: 'post', > postBody: postFormData, > onComplete: NamedActionResponseHandler} > ); > } > function NamedActionResponseHandler(theResponse) > { > var elementThatTriggeredEvent = NamedActionElement; > > //do stuff based on values i have encoded into the element and > //the data returned in theResponse > } change this function to return another function. Something like this: function NamedActionResponseHandler(NamedActionElement, etc) { return function(theResponse) { //do stuff based on values i have encoded into the element and //the data returned in theResponse } } And then call it like this: onComplete: NamedActionResponseHandler(theElement), -- Michael Peters Developer Plus Three, LP _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs