Passing value from parent form to child form using javascript showModalDialog

if I want to pass my value to the confirmation field !!! so let's say that I want to remove item No. 1, so I checked the box and then clicked the delete button. a popup comes out with part number 1 in it.

I implemented a popup using the show modal dialog (JavaScript), but I still cannot get the parent value in the child form!

Also, if I have item number 1 and item number 2, I want both to appear in the confirmation window !!

Any suggestion would be greatly appreciated.

+3
source share
3 answers

showModalDialog , , (, OnLoad) window.dialogArguments.

, ( 10 , ).

: , showModalDialog. HTML "Parent.htm" "Child.htm". Parent.htm:

<HTML>
<input type=button value="CustomConfirm" 
    onclick="ShowMyDialog()">
<script language="javascript">
function ShowMyDialog()
{
    var obj = new Object(); 
    obj.data1 = 'some data 1';
    obj.data2 = 'some data 2';
    showModalDialog('Child.htm', obj, '');
    alert(obj.returnvalue);
}
</script>
</HTML>

Child.htm:

<HTML>
<body onload="ReadPassedData()" 
    onunload="DoUnload()">
<input type=text id="textbox1">
<br>
<input type=text id="textbox2">
<br>
<br>
Return value:<br>
<input type=text id="textbox3" 
    value="type something">
</body>
<script language="javascript">
function ReadPassedData()
{
    var obj = window.dialogArguments;
    var tb1 = document.getElementById('textbox1');
    tb1.value = obj.data1; 
    var tb2 = document.getElementById('textbox2');
    tb2.value = obj.data2; 
}
function DoUnload()
{
    var obj = window.dialogArguments;
    obj.returnvalue = textbox3.value;
}
</script>
</HTML>

Parent.htm "CustomConfirm". , ( " 1" " 2" ), , , , . .

( , showModalDialog), , .

2. , - :

var myarray = new Array();
myarray[0] = "Bob Smith";
myarray[1] = "Doug Jones";
myarray[2] = "Englebert Humperdinck";
var ret = showModalDialog('Child.htm', myarray, '');
alert(ret); // this will display whatever the child set for its
    // window.returnValue

, , :

var myarray = window.dialogArguments;
alert(myarray[0]); // or whatever

, true false ( returnvalue ). , window.returnValue. , , , "" "", window.returnValue true false .

+1

, :

window.opener.document.getElementById("whatever").value = whatever;
+1

, WindowTrigger.aspx, , , script WindowContainer.aspx, showModalDialog.

     <asp:Button ID="btnDate" Text="Display Window" OnClientClick="WindowOpen()"       runat="server" />

<script language="javascript" type="text/javascript">
         function WindowOpen() {
             var theAdmin = new Array();
             theAdmin["id"] = '';
             theAdmin["name"] = '';
             var winopts = "dialogWidth:290px;dialogHeight:220px;scroll:no;resizable:no;status:no;unadorned:yes";

             var admStatus = window.showModalDialog("http://localhost:51836/WindowContainer.aspx", theAdmin, winopts);
             alert(theAdmin["id"]);
             alert(theAdmin["name"]);
         }
     </script> 

script 'theAdmin', ,

WindowContainer.aspx, , .

    <asp:ListBox ID="ddlUsers" runat="server" Rows="10" SelectionMode="Multiple">
       <asp:ListItem Text="Chennai" Value="044"></asp:ListItem>
       <asp:ListItem Text="Hyderabad" Value="040"></asp:ListItem>
       </asp:ListBox> 
   <asp:Button ID="btnDate" Text="Date" OnClientClick="submitForm()"  runat="server" />  

<script language="javascript" type="text/javascript">
         function submitForm() {
             var lstAdmins = document.getElementById('ddlUsers');
             var SelectedIDs = "";
             var SelectedNames = "";
                 if (lstAdmins != null) {
                     for (i = 0; i < lstAdmins.options.length; i++) {
                         if (lstAdmins.options[i].selected) {
                             if (SelectedIDs == '')
                                 SelectedIDs = lstAdmins.options[i].value;
                             else
                                 SelectedIDs += ";" + lstAdmins.options[i].value;

                             if (SelectedNames == '')
                                 SelectedNames = lstAdmins.options[i].text;
                             else
                                 SelectedNames += ";" + lstAdmins.options[i].text;
                         }
                     }
                 }
             var theAdmin = dialogArguments;
             theAdmin["id"] = SelectedIDs;
             theAdmin["name"] = SelectedNames;
             window.returnValue = "OK";
             self.close();
         }

     </script> 

"044; 040;" ", "; . , ( theAdmin) , ( ).

0

Source: https://habr.com/ru/post/1718766/


All Articles