View Full Version : Lag in passing values from popup to opener?

07-15-2009, 09:06 AM
Hey all,
I am working on an application that has a popup form. When the form is submitted, the values in the form are passed to a variable in the opener window code. The popup is closed and focus returned to the opener.

The problem that seems to arise for me is that the new value for the variable is only set after a 'lag' in the code; it only updates if I display an alert box after focus is returned to the opener. If I don't display the alert box, then in the first occurrence, the variable stays blank. Subsequent events result in the variable having the value of the popup window previously submitted, not the last one, as expected. Testing in Opera (was told as long as the application works in one browser, it's okay - experimental phase :p)

Relevant code snippets below. Any suggestions/fixes?
Thanks for your help!

Main Code (createUnit is a global variable):

alert(newUnitData); //this prevents the lag; if removed, lag occurs.
if(newUnitData != '') {
do stuff }

Popup Code (dataString is a global variable):

//this function is called when the form is submitted
function submitUnit() {
var numElements = document.forms['newUnit'].elements.length;
dataString += document.forms['newUnit'].elements[i].value + ',';
if(window.opener && !window.opener.closed) {
window.opener.newUnitData = dataString;