You are here: Reference > JavaScript > client-side > dialog > properties > returnValue (window)

returnValue property (window)

Browser support:
3
Specifies or retrieves the value returned from a modal dialog window.
Modal dialog windows can be created with the showModalDialog method. The showModalDialog method does not return until the modal dialog is closed. With the returnValue property, the value returned by the showModalDialog method can be retrieved. This property facilitates the communication between the opener and the dialog window.
The returnValue property is supported in Firefox from version 3.

Syntax:

object.returnValue;
You can find the related objects in the Supported by objects section below.
This property is read/write.

Possible values:

Variant that specifies or retrieves the return value.
Default: this property has no default value.

Example HTML code 1:

This example shows how to generate a modal dialog, and how to communicate between the opener and the modal window:
Code
modal.htm
<head>
    <script type="text/javascript">
        function UpdateFields (newFore, newSur) {
            var forename = document.getElementById ("forename");
            var surname = document.getElementById ("surname");
            forename.value = newFore;
            surname.value = newSur;
        }

        function ShowModal () {
            var forename = document.getElementById ("forename");
            var surname = document.getElementById ("surname");

            var sharedObject = {};
            sharedObject.forename = forename.value;
            sharedObject.surname = surname.value;
            
            if (window.showModalDialog) {
                var retValue = showModalDialog ("modal.htm", sharedObject, "dialogWidth:200px; dialogHeight:200px; dialogLeft:300px;");
                if (retValue) {
                    UpdateFields (retValue.forename, retValue.surname);
                }
            }
            else {
                    // we want similar functionality in Opera, but it's not modal!
                var modal = window.open ("modal.htm", null, "width=200,height=200,left=300,modal=yes,alwaysRaised=yes", null);
                modal.dialogArguments = sharedObject;
            }
        }
    </script>
</head>
<body>
    Forename: <input type="text" id="forename" value="Alan"/><br />
    Surname: <input type="text" id="surname" value="Smith"/>
    <br /><br />
    <button onclick="ShowModal ()">Edit fields with modal dialog!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content