Javascript-value between the two forms to achieve code
There is also a function window.showModalDialog javascript can also open a new form, but he opened a modal window, how the parent form and child form in between the pass worth it? We look at the function definition: vReturnValue = window.showModalDialog (sURL [, vArguments] [, sFeatures])
Parameters:
sURL - required parameter, type: string. Used to specify the dialog box to display the document's URL.
vArguments - optional parameters, type: variant. Used to pass parameters to the dialog box. Parameter type passed open, including an array of other. Dialog box to get passed through window.dialogArguments incoming parameters.
sFeatures - optional parameters, type: string. Used to describe the appearance of the dialog box and other information, you can use the following one or a few, with a semicolon ";" to separate.
dialogHeight: dialog height, not less than 100px, IE4 in dialogHeight and dialogWidth default units are em, but IE5 is px, to facilitate their view, the way in defining the modal dialog box, make use of px units.
dialogWidth: dialog width.
dialogLeft: the distance from the screen to the left.
dialogTop: the distance from the screen.
center: (yes | no | 1 | 0): the window is centered, default yes, but you can specify the height and width.
help: (yes | no | 1 | 0): whether to display the Help button, default yes.
resizable: (yes | no | 1 | 0) [IE5 +]: it can be resized. Default no.
status: (yes | no | 1 | 0) [IE5 +]: whether to display the status bar. The default is yes [Modeless] or no [Modal].
scroll: (yes | no | 1 | 0 | on | off): specify whether to display the dialog box scroll bar. The default is yes.
Such as: "dialogWidth = 200px; dialogHeight = 100px"
Therefore, we can window.dialogArguments parameters by value between the two forms, such as the following two pages: FatherPage.htm:
Code:
<script type="text/javascript"> function OpenChildWindow() { window.showModalDialog('ChildPage.htm',document.getElementById('txtInput').value); } </script> <input type="text" /> <input type="button" value="OpenChild" /> ChildPage.htm: Code is as follows : <body onload="Load()"> <script type="text/javascript"> function Load() { document.getElementById('txtInput').value=window.dialogArguments ; } </script> <input type="text" /> </body> The above just passing a simple string, we can also pass an array , If :FatherPage.htm: XML-Code: Code is as follows : <script type="text/javascript"> function OpenChildWindow() { var args = new Array(); args[0] = document.getElementById('txtInput').value; window.showModalDialog('ChildPage.htm',args); } </script> <input type="text" /> <input type="button" value="OpenChild" />ChildPage.htm: XML-Code: <script type="text/javascript"> function Load() { document.getElementById('txtInput').value=window.dialogArguments[0] ; } </script> Similarly we can also pass an object, such as :FatherPage.htm: XML-Code: Code is as follows : <script type="text/javascript"> function OpenChildWindow() { var obj = new Object(); obj.name = document.getElementById('txtInput').value; window.showModalDialog('ChildPage.htm',obj); } </script> <input type="text" /> <input type="button" value="OpenChild" /> ChildPage.html: XML-Code: Code is as follows : <script type="text/javascript"> function Load() { var obj = window.dialogArguments; document.getElementById('txtInput').value=obj.name ; } </script> The above are from parent to child form, then how to pass a value from the subform to the parent form by value? ? In fact, through the window.returnValue can obtain the value of the child form ,window.returnValue As with the window.dialogArguments , Can be any string variable, including , Array, object, etc. . If :FatherPage.html: XML-Code: Code is as follows : <script type="text/javascript"> function OpenChildWindow() { var obj = new Object(); obj.name = document.getElementById('txtInput').value; var result = window.showModalDialog('ChildPage.htm',obj); document.getElementById('txtInput').value = result.name; } </script> <input type="text" /> <input type="button" value="OpenChild" /> ChildPage.html: XML-Code: Code is as follows : <body onload="Load()"> <script type="text/javascript"> function Load() { var obj = window.dialogArguments; document.getElementById('txtInput').value=obj.name ; } function SetValue() { var obj = new Object(); obj.name = document.getElementById('txtInput').value; window.returnValue = obj; window.close(); } </script> <input type="text" /> <input type="button" value="SetFather" /> </body>