Click to See Complete Forum and Search --> : how do I pass a var FROM a modal dialog?
mitya
12-01-2003, 08:41 AM
Hi all
I have a modal dialog window which appears to prompt a question. When the user selects a choice in this window, I want the window to close and then pass that information to its parent (source) page.
So how do I get the page which launched the modal dialog to receive vars or do something 'onClose' so to speak? For example, if I have a function on the main page with a simple alert('hello') on, how would I call that upon closing the modal dialog?
Thanks in advance.
Gollum
12-01-2003, 09:16 AM
How are you creating your modal dialog? Is it using the confirm() function? If so, then the answer is easy, since the dialog will close when one of the choices has been clicked, and the return value from confirm() is a boolean that is true for "OK" and false for "Cancel".
If not, can you let us know how you have defined your dialog?
mitya
12-01-2003, 09:18 AM
Sorry I should be more specific. It's not a confirm box, that'd be fine. It's a modal dialog window (I think that's what it's called) in which a seperate page is loaded into it and it takes preference of focus over the parent page (i.e. you can't click out of it).
Hope this clears it up :)
Webskater
12-01-2003, 09:52 AM
When you open your modal window you must reference the window as 'window'. Sounds daft but looks like:
window.showModalDialog('SomePage.asp',window,'dialogHeight:400px; dialogWidth:600px; help:no; status:no;');
i.e. where you might put '_blank' to force a new window to open when using the normal window.open command you must put 'window' (not in inverted commas as it is an object).
You can then use a function like this on your modal page:
<script language="javascript">
function close1(FirstName,Surname)
{
var callerWindowObj = dialogArguments;
callerWindowObj.firstname = FirstName;
callerWindowObj.surname = Surname;
callerWindowObj.UpdateSelect();
window.close();
}
</script>
The line ...
var callerWindowObj = dialogArguments
... gives the dialogWindow a reference to the window that opens it.
mitya
12-01-2003, 10:03 AM
Thanks for that Skater, I'll see how I get on :)
Webskater
12-01-2003, 10:04 AM
When you open your modal window you must reference the window as 'window'. Sounds daft but looks like:
window.showModalDialog('SomePage.asp',window,'dialogHeight:400px; dialogWidth:600px; help:no; status:no;');
i.e. where you might put '_blank' to force a new window to open when using the normal window.open command you must put 'window' (not in inverted commas as it is an object).
You can then use a function like this on your modal page:
<script language="javascript">
function close1(FirstName,Surname)
{
var callerWindowObj = dialogArguments;
callerWindowObj.firstname = FirstName;
callerWindowObj.surname = Surname;
callerWindowObj.UpdateSelect();
window.close();
}
</script>
The line ...
var callerWindowObj = dialogArguments
... gives the dialogWindow a reference to the window that opens it.