passing data from parent window to popup

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • meenakshia
    New Member
    • Jun 2008
    • 33

    passing data from parent window to popup

    hi forum
    i have read a lot of articles regarding passing data from popup to parent up but i m looking for the opposite
    that is
    from parent to popup window
    pls help me in this regard
    i have three input fields in parent window
    and three in popup window

    parent.htm
    Code:
    <script language="JavaScript">
    function newWindow(file,window)
    {msgWindow=open(file,window,'scrollbars=yes,resizable=no,width=550,height=400');
    if (msgWindow.opener == null) msgWindow.opener = self;
    }
    </script>
    
    <input type="button" value="Search" onClick="newWindow('popup.htm','window2')">
    														
    <form name="inputform1" >
    <table><tr><td>Stitching Number
    </td>
    <td><input type="text" name="txtasno" tabindex="1"  size="20">
    </td>
    <td>Remarks
    </td>
    <td><input type="text" name="txtremarks" tabindex="5"  size="20">
    </td>
    <td>Sales Person
    </td>
    <td><input type="text" name="txtsperson" tabindex="6"  size="20">
    </td>
    </tr></table>
    </form>
    popup.htm
    Code:
    <form name="outputform1" >
    <table><tr><td>Stitching Number
    </td>
    <td><input type="text" name="txtasno" tabindex="1"  size="20">
    </td>
    <td>Remarks
    </td>
    <td><input type="text" name="txtremarks" tabindex="5"  size="20">
    </td>
    <td>Sales Person
    </td>
    <td><input type="text" name="txtsperson" tabindex="6"  size="20">
    </td>
    </tr></table>
    </form>
    i hope there is a way to do this
    smile always:)
    anand
    Last edited by meenakshia; Jun 27 '08, 04:27 AM. Reason: code was incomplete
  • vikas251074
    New Member
    • Dec 2007
    • 198

    #2
    How can you pass a value without submitting a form?

    I mean, you should have button in the input form. Then you can modify the popup.htm as follows

    Code:
    <form name="outputform1" >
    <table><tr><td>Stitching Number
    </td>
    <td><%=request.form("txtasno")%>
    </td>
    <td>Remarks
    </td>
    <td><%=request.form("txtremarks")%>
    </td>
    <td>Sales Person
    </td>
    <td><%=request.form("txtsperson")%>
    </td>
    </tr></table>
    </form>
    This may help you.

    Thanks and regards,
    Vikas
    Last edited by acoder; Nov 23 '11, 11:51 AM. Reason: Added [code] tags

    Comment

    • meenakshia
      New Member
      • Jun 2008
      • 33

      #3
      hi thanks and yes it was a mistake i made but then the problem is still the same
      i need to solve the way to pass data from parent window to popup window
      i have modified the code accordingly

      Comment

      • vikas251074
        New Member
        • Dec 2007
        • 198

        #4
        What is the error message?

        Regards,
        Vikas

        Comment

        • realin
          Contributor
          • Feb 2007
          • 254

          #5
          hi i dont know if this is going to helpyou or no, but this one is simple sending data from parent window to child window. hope this helps

          Parent window code:
          Code:
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
          <title>send data over child window</title>
          <script language="javascript" type="text/javascript">
          var winRef;
          function open_win(){
          winRef=window.open("child.htm");
          }
          
          function send_data(){
          var g=document.getElementById("_text").value;
          winRef.document.getElementById("_child").value=g;
          }
          </script>
          </head>
          
          <body>
          
          <a href="javascript:void(0);" onclick="open_win();">open window</a><br />
          <input type="text" name="_text" id="_text" /><br />
          
          <a href="javascript:void(0);" onclick="send_data();">Send data</a>
          </body>
          </html>
          Child Window Code:
          Code:
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
          <title>Untitled Document</title>
          </head>
          
          <body>
          
          <input type="text" name="_child" id="_child" value=""/>
          </body>
          </html>
          cheers !!
          Last edited by acoder; Nov 23 '11, 11:51 AM.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by vikas251074
            How can you pass a value without submitting a form?

            I mean, you should have button in the input form. Then you can modify the popup.htm as follows...
            You can pass values without submitting a form. The code you posted assumes the data was posted and just displays it using ASP. Since there are no input fields, there's no need for the form tag.

            Also, don't forget to use code tags when posting code.

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Originally posted by meenakshia
              i have read a lot of articles regarding passing data from popup to parent up but i m looking for the opposite
              that is from parent to popup window
              realin has posted code which you should be able to adapt to your requirements. Remember though that the popup window will not be available immediately, so you will need something to trigger the passing of value, e.g. a button.

              Finally, the language attribute of the script tag is deprecated - use type="text/javascript" instead.

              Comment

              • meenakshia
                New Member
                • Jun 2008
                • 33

                #8
                hi realin
                thanks for the help and yes it is working fine
                only thing that i require more is that is it possible to open the new window and copy the data with only link click?
                or i have to do it this way only?
                thanks
                anand

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  You can do that, but you will need to use a timeout to check for the existence of the window. When it's ready, you can pass the data. An alternative is to call the function in the parent from the popup body onload.

                  Comment

                  • realin
                    Contributor
                    • Feb 2007
                    • 254

                    #10
                    Originally posted by meenakshia
                    hi realin
                    thanks for the help and yes it is working fine
                    only thing that i require more is that is it possible to open the new window and copy the data with only link click?
                    or i have to do it this way only?
                    thanks
                    anand
                    hiya,

                    well i guess u can call the send_data() function inside the other, ofcourse u can use setTimeout() so as to avoid any sorta problem. But if also integrated a check for the child window, meaning if the child window doesnt exist, it will alert the user and then it won't try to transfer data. Look at the modified code, nevertheless the childwindow code remains the same.

                    Code:
                    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                      
                       <html xmlns="http://www.w3.org/1999/xhtml">
                      
                       <head>
                      
                       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                      
                       <title>send data over child window</title>
                      
                       <script language="javascript" type="text/javascript">
                      
                       var winRef;
                      
                       function open_win(){
                      
                       winRef=window.open("popup.htm");
                      send_data();
                       }
                      
                        
                      
                       function send_data(){
                      if(winRef==null){
                      alert("Child window doesn't exist");
                      return false;
                      }
                      else{
                       var g=document.getElementById("_text").value;
                      
                       winRef.document.getElementById("_child").value=g;
                       }
                      
                       }
                      
                       </script>
                      
                       </head>
                      
                        
                      
                       <body>
                      
                        
                      
                       <a href="javascript:void(0);" onclick="open_win();">open new child window and send data</a><br />
                      
                       <input type="text" name="_text" id="_text" /><br />
                      
                        
                      
                       <!--<a href="javascript:void(0);" onclick="send_data();">Send data</a>-->
                      
                       </body>
                      
                          </html>


                    cheers !!
                    Last edited by acoder; Nov 23 '11, 11:50 AM.

                    Comment

                    • snehaarora
                      New Member
                      • Jul 2008
                      • 1

                      #11
                      Hello Friends !!

                      I have read all the above posts and seems interesting.
                      I have one query for the above post.
                      you are passing values from parent to child window. and now i need to pass the same values that are used in above code to passed back to parent window in a new text box thru child window using a link on child windows elements.

                      Can anybody help me regarding this.


                      Thanks in advance.

                      Regards,

                      Sneha

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        Hi Sheha, welcome to Bytes.

                        Use window.opener to refer to the parent from the child window.

                        Comment

                        • Mahesh Reddy

                          #13
                          To open the child window this is the code used in parent window
                          Code:
                          <form method=post action='' name=f1>
                          <table border=0 cellpadding=0 cellspacing=0 width=550> <tr>
                          <td ><font size=2 face='Verdana'>Your Name</font><input type=text name='p_name' size='8'> 
                          <a href="javascript:void(0);" NAME="My Window Name" title=" My title here "
                          onClick=window.open("child3.html","Ratting",
                          "width=550,height=170,left=150,top=200,toolbar=1,status=1,");>Click here to open the child window</a>
                          
                          </td></tr> </table></form>
                          Inside the Child window code is here
                          Code:
                          <html>
                          <head>
                          
                          <script langauge="javascript">
                          function post_value(){
                          opener.document.f1.p_name.value = document.frm.c_name.value;
                          self.close();
                          }
                          </script>
                          
                          <title>(Type a title for your page here)</title>
                          </head>
                          
                          
                          <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
                          
                          <form name="frm" method=post action=''>
                          <table border=0 cellpadding=0 cellspacing=0 width=250>
                          
                          
                          <tr><td align="center"> Your name<input type="text" name="c_name" size=12 value=test> <input type=button value='Submit' onclick="post_value();">
                          </td></tr>
                          </table></form>

                          Comment

                          Working...