Hi folks,
I've got a need for one of my functions to accept a callback function as
a parameter (if that's even the right way to do it). Anyway, I'm having
trouble and I'm hoping that someone here could help me.
This particular situation deals with a parent page, and a child page
which is loaded inside of a thickbox window.
So the parent page has a function that looks like this:
function DisplayScreen(currentScreenString, methodName, contentID){
if(arguments.length < 3){
contentID = "MainContent";
}
if(currentScreenString.length){
gCurrentScreen = currentScreenString;
}
$.AjaxCFC({
url: "CFC/Display.cfc",
method: methodName,
data: {},
unnamedargs: false,
serialization: "html",
success: function(data) {
$("#" + contentID).empty().append(data);
// add the hover effect if possible...
$(".ScoreBox").mouseover(
function(){
$(this).addClass("OnHover");
}).mouseout(
function(){
$(this).removeClass("OnHover");
});
},
error: function(){
DisplayScreen("homeScreen", "displayHomeScreen")
}
});
}
in the child window I've got a code snippet that looks like this:
if(parent.gCurrentScreen !== "newTitleLoanEvaluation"){
parent.DisplayScreen('newTitleLoanEvaluation','displayNewTitleLoanEvaluationWorksheet',TestFunction);
elmLastName = parent.document.getElementById("LastNameID");
elmFirstName = parent.document.getElementById("FirstNameID");
elmCustomerNumber = parent.document.getElementById("CustomerNumberID");
elmLastName.value = data.LASTNAME;
elmFirstName.value = data.FIRSTNAME;
elmCustomerNumber.value = data.CUSTOMERNUMBER;
}
so what I'm doing is updating the parent page with some data that are
the results of a search done in the child page. This is great if the
parent page is already the one that I want updated, but the user can get
to this search window from anywhere in the application, so what I need
to do is switch the parent page to the one I'm wanting to update before
I get the three elements (Last,First,CustomerNumber) and then try to set
their values.
Since parent.DisplayScreen() itself makes an ajax call. So, I want a way
to tell that function that once it's though if it's been called with a
call back function it should execute it on return.
I feel like there's a simple concept I'm missing here. Essentially I
*think* that my function definition would look something like:
function test(a, b, returnFunc){
var c = a + b;
//... bah! This is where I go bananas. My first instinct is to say
something like...
eval(returnFunc); // but that seems wrong...
//...so what about...
returnFunc();
}
... but I don't want to waste time running down paths that may go
nowhere. Can someone on the list give me a quick hand understanding how
to do this?
Thanks heaps,
Chris
--
http://cjordan.us