Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: passing data from parent window to popup

  1. #1
    Join Date
    Nov 2007
    Posts
    69
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Default 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 meenakshi; 06-27-2008 at 04:28 AM. Reason: code was incomplete

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    I hope you are looking for a way to copy the value from the input fields in your parent window to the popup window input fields. If so you can use the following code:
    Code:
    window.onload = function(){
    	var pw = parent.window;
    	if(pw){
    		var inputFrm = pw.document.forms['inputform1'];
    		var outputFrm = document.forms['outputform1'];
    		
    		outputFrm.elements['txtasno'].value = inputFrm.elements['txtasno'].value;
    		outputFrm.elements['txtremarks'].value = inputFrm.elements['txtremarks'].value;
    		outputFrm.elements['txtsperson'].value = inputFrm.elements['txtsperson'].value;
    	}
    }
    Put the above code in the <script> element of your POPUP WINDOW page. Please note that you can have only one onload event on the window object if you have multiple onload events then you need to club them together, if you don't have multiple onload events leave this point.

  3. The Following User Says Thank You to codeexploiter For This Useful Post:

    meenakshi (06-27-2008)

  4. #3
    Join Date
    Nov 2007
    Posts
    69
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Default

    hi wow thanks
    i will try to use it and get back to u with the successful result hopefully
    thanks
    smile always
    anand

  5. #4
    Join Date
    Nov 2007
    Posts
    69
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Default

    hi
    and how should i use multiple onload event?
    i m asking because in popup i already have one onload running
    should i use a new function and put both the functions in it and then go for onload for the new function?
    is that the way?
    smile always
    anand

  6. #5
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Quote Originally Posted by meenakshi View Post
    hi
    and how should i use multiple onload event?
    i m asking because in popup i already have one onload running
    should i use a new function and put both the functions in it and then go for onload for the new function?
    is that the way?
    smile always
    anand
    You can insert your existing onload code inside the window.onload function that I've provided, which will be get executed correctly. I don't think for that purpose you need to create another new function.

  7. The Following User Says Thank You to codeexploiter For This Useful Post:

    meenakshi (06-30-2008)

  8. #6
    Join Date
    Nov 2007
    Posts
    69
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by codeexploiter View Post
    I hope you are looking for a way to copy the value from the input fields in your parent window to the popup window input fields. If so you can use the following code:
    Code:
    window.onload = function(){
    	var pw = parent.window;
    	if(pw){
    		var inputFrm = pw.document.forms['inputform1'];
    		var outputFrm = document.forms['outputform1'];
    		
    		outputFrm.elements['txtasno'].value = inputFrm.elements['txtasno'].value;
    		outputFrm.elements['txtremarks'].value = inputFrm.elements['txtremarks'].value;
    		outputFrm.elements['txtsperson'].value = inputFrm.elements['txtsperson'].value;
    	}
    }
    Put the above code in the <script> element of your POPUP WINDOW page. Please note that you can have only one onload event on the window object if you have multiple onload events then you need to club them together, if you don't have multiple onload events leave this point.
    hi
    well i tried to do so but the popup window does not show anything in the input field
    it is still blank

  9. #7
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Hi Meenakshi,

    I am so sorry that I've made one mistake in my initial code thats why it fired an error and stucked at its execution. I've corrected my code and it is working now correctly

    Code:
    window.onload = function(){
    				var pw = window.opener;
    				if(pw){
    					var inputFrm = pw.document.forms['inputform1'];
    					var outputFrm = document.forms['outputform1'];
    		
    					outputFrm.elements['txtasno'].value = inputFrm.elements['txtasno'].value;
    					outputFrm.elements['txtremarks'].value = inputFrm.elements['txtremarks'].value;
    					outputFrm.elements['txtsperson'].value = inputFrm.elements['txtsperson'].value;
    				}
    			}
    I had used parent.window instead of window.opener I am extremely sorry about this error. Now the thing you wanted is working fine.

  10. The Following User Says Thank You to codeexploiter For This Useful Post:

    meenakshi (06-30-2008)

  11. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You can also pass values from parent window to child windows from the parent page if the child window is opened with javascript and that instance is assigned to a variable on the page in the parent window.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  12. The Following User Says Thank You to jscheuer1 For This Useful Post:

    meenakshi (06-30-2008)

  13. #9
    Join Date
    Nov 2007
    Posts
    69
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Default

    hi codex
    wow it works and thanks a lot for helping me to find a solution
    thanks once again
    smile always
    anand

  14. #10
    Join Date
    Nov 2007
    Posts
    69
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Default

    hi codex one more question
    i m attaching the files and the ms access database
    what i m doing is that in the popup file ie daily1.htm i have a search field which i have linked with ms access database and get results.i have also linked with the help of ur code the parent file with daily1.htm which transfer the data to search field.
    only issue is that the data gets transferred to pop up search field but does not filter the records(pls enter stitching number as 28 in parent.htm) unless tab is pressed.
    i might be sounding confusing but if u can see and tell me is there a way to do the transfer and load the search field
    smile always
    anand
    attach file-testing.zip

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •