1. PASS Parameters to window. showmodaldialog:
Window. showmodaldialog Method Second Parameter It indicates the parameter value that the parent form passes to the modal form, which can be any object or array), or it can directly be null without passing parameters. This parameter is optional. The prototype is as follows:
Vreturnvalue = Window. showmodaldialog (Surl [, varguments] [, sfeatures])
Example:
VaR Params = [document. getelementbyid ("tbcorpname"), document. getelementbyid ("tbcorpid")]; // Parameter
VaR returnvalue = Window. showmodaldialog ("selectclient. aspx ", Params , "Dialogleft: 1px; dialogtop: 1px; dialogwidth: 500px; dialogheight: pixel PX; resizable: Yes; Status: No ");
In this way, we can Use the window. dialogarguments attribute in the modal form to obtain the passed parameters.
Function setcorpname (corpname, corpid)
{
VaR Params = Window. dialogarguments; // obtain the parameters passed in by the parent form;
Params [0]. value = corpname; // set the value of the text field in the parent form.
Params [1]. value = corpid;
Self. Close (); // close the modal form.
}
This method has a problem in Firefox. . If the modal form is a dynamic page (ASPX page), if the mode form involves interaction with the server, such as a "query" event, after clicking the "query" button, in Firefox, Windows is no longer supported. the dialogarguments property gets the passed parameters. That is to say, when the form is displayed for the first time in Firefox, the parameters passed by the parent form can be obtained. Any other interaction with the server will cause the parameter information to be discarded. This problem does not exist in IE. Therefore, if you want to access the objects in the parent form in the modal form, it is best not to use this method. See the second method below:
2 . Obtain the return value from the modal form:
The Return Value of the window. showmodaldialog method is the return value of the modal form. Pass Set the window. returnvalue attribute in the modal form.
// Parent form Code :
VaR returnvalue = Window. showmodaldialog ("Selectclient. aspx", null, "dialogleft: 1px; dialogtop: 1px; dialogwidth: 500px; dialogheight: pixel PX; resizable: Yes; Status: No ");
If (returnvalue)
{
VaR arrvalue = returnvalue. Split (":"); // values are separated by colons.
Document. getelementbyid ("tbcorpname"). value = arrvalue [0];
Document. getelementbyid ("tbcorpid"). value = arrvalue [1];
}
// Modal form code:
Function setcorpname (corpname, corpid)
{
Window. returnvalue = Corpname + ":" + corpid; // you can specify the value returned from the modal form.
Self. Close ();
}
In addition, add the following in the <Base target = "_ Self"> </base>
This prevents the opening of the new form when the button is clicked in the modal form for submission.