Click to See Complete Forum and Search --> : Pop Up Variables to function in Parent Window


ccurle
12-07-2006, 12:09 PM
I have a form that is a pop up window, and when you fill it out, the variables get sent to a javascript function in the parent window.

If I put in an alert in the function, I see that the variables are being passed, however, they aren't going past the function.

The form is to add a categoy. The function sends the variable to a php page and updates it via ajax. If I put this function on the parent page, it works, but when it comes from the pop up, the variables are there, but the function doesn't send the results to the php page.

Here is the code for the pop up
var newCat = null;
function addCat() {
if (newCat && !newCat.closed) newCat.close();
newCat = open('admin_create_category.php','newCat','left=300,top=85,width=350,height=270,status=0');
}

Here is the code in the pop up window
function setOpener(oForm) {
if (opener && !opener.closed) {
var newChanName = oForm.chanName.value;
var newChanDesc = oForm.chanDesc.value;
opener.addCategory('channelResult',newChanName,newChanDesc);
self.close();
return false;
}
}


Here is the function in the parent window that sends to php page
function addCategory(div_id,cn,cd) {
subject_id = div_id;
var channelID = document.program.Channel[document.program.Channel.selectedIndex].value;
http.open("GET", "admin_create_category_result.php?ChanName=" + escape(cn) + "&ChanDesc=" + escape(cd) + "&ChannelGK=" + escape(channelID), true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}

Like I said, if I run the function addCategory from the parent window, it works, but when it comes from the popup it doesn't.

I have added an alert(); to the addCategory function and the variables do show up.

Is there something I am not doing or need to do to make this run?

Thanks in advance.

ccurle
12-07-2006, 02:54 PM
Update.

I put the alert function back in and let the rest of the script work.

After I clicked the ok button of the alert box, it worked. If I take the alert out, it doesn't work.

Is there a timing issue going on?

I have noticed if I click the OK button from the alert box to soon, the script doesn't work.

If it is a timing issue, how do I let the function have more time?

Mr J
12-07-2006, 03:55 PM
Put the self.close() on a timer, see if that helps

setTimeout("self.close()",1000)

ccurle
12-07-2006, 05:33 PM
That did it.

I tried everything in the parent window and it was the popup all along.

It's strange how the alert worked properly, but nothing else did.

Thanks for the tip. I really appreciate it.