Javascript: how to wait for the first action to finish and trigger a function

I run the following code in a button on web

form.submit()

parent.closeDialog(‘availForm’, ‘dialogAvail’)

the second function, hides the iframe that contains the document. The problem is that the second function triggers immediately and does not wait for form to be submitted which results in problems. How do I make it wait for the form to be submitted and then hide the dialog?

Thanks

Basir

Subject: javascript: how to wait for the first action to finish and trigger a function

You can perform the required functionality by creating a timer event on the parent which checks the child window (eg. repeatedly checks for a valid field handle) and closes the child window when your check fails.

Here’s one way to do it…

Firstly you need a handle from the parent window to the child window so when you open the child window your code should be something like:

childWindow = window.open(windowURL,“_blank”,windowoptions);

Note: childWindow should be a global variable.

Then in the closeDialog function on the parent form you could check for the existence of a field on the child form using a timer function. When the child form has been submitted the field should evaluate to null and then the window is closed.

The closeDialog() function should have the following line:

timerID = setInterval(“checkChildSubmitted()”, 100);

Note: timerID should be a global variable.

You’ll need to create a function called ‘checkChildSubmitted()’ with the following code:

function checkChildSubmitted()

{

childWindowFieldHandle = childWindow.document.forms[0].FieldName;



if (childWindowFieldHandle = null)

{

	childWindow.close();

	clearInterval(timerID);

}

}

Hope this helps.

Alex