Pass parameters to the modal form and obtain the return value

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.