By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,625 Members | 1,448 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,625 IT Pros & Developers. It's quick & easy.

passing data from parent window to popup

meenakshia
P: 33
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
Expand|Select|Wrap|Line Numbers
  1.  
  2. <script language="JavaScript">
  3. function newWindow(file,window)
  4. {msgWindow=open(file,window,'scrollbars=yes,resizable=no,width=550,height=400');
  5. if (msgWindow.opener == null) msgWindow.opener = self;
  6. }
  7. </script>
  8.  
  9. <input type="button" value="Search" onClick="newWindow('popup.htm','window2')">
  10.  
  11. <form name="inputform1" >
  12. <table><tr><td>Stitching Number
  13. </td>
  14. <td><input type="text" name="txtasno" tabindex="1"  size="20">
  15. </td>
  16. <td>Remarks
  17. </td>
  18. <td><input type="text" name="txtremarks" tabindex="5"  size="20">
  19. </td>
  20. <td>Sales Person
  21. </td>
  22. <td><input type="text" name="txtsperson" tabindex="6"  size="20">
  23. </td>
  24. </tr></table>
  25. </form>
  26.  
popup.htm
Expand|Select|Wrap|Line Numbers
  1. <form name="outputform1" >
  2. <table><tr><td>Stitching Number
  3. </td>
  4. <td><input type="text" name="txtasno" tabindex="1"  size="20">
  5. </td>
  6. <td>Remarks
  7. </td>
  8. <td><input type="text" name="txtremarks" tabindex="5"  size="20">
  9. </td>
  10. <td>Sales Person
  11. </td>
  12. <td><input type="text" name="txtsperson" tabindex="6"  size="20">
  13. </td>
  14. </tr></table>
  15. </form>
  16.  
i hope there is a way to do this
smile always:)
anand
Jun 27 '08 #1
Share this Question
Share on Google+
12 Replies


vikas251074
100+
P: 198
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

Expand|Select|Wrap|Line Numbers
  1. <form name="outputform1" >
  2. <table><tr><td>Stitching Number
  3. </td>
  4. <td><%=request.form("txtasno")%>
  5. </td>
  6. <td>Remarks
  7. </td>
  8. <td><%=request.form("txtremarks")%>
  9. </td>
  10. <td>Sales Person
  11. </td>
  12. <td><%=request.form("txtsperson")%>
  13. </td>
  14. </tr></table>
  15. </form>
  16.  
This may help you.

Thanks and regards,
Vikas
Jun 27 '08 #2

meenakshia
P: 33
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
Jun 27 '08 #3

vikas251074
100+
P: 198
What is the error message?

Regards,
Vikas
Jun 27 '08 #4

realin
100+
P: 254
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:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  6. <title>send data over child window</title>
  7. <script language="javascript" type="text/javascript">
  8. var winRef;
  9. function open_win(){
  10. winRef=window.open("child.htm");
  11. }
  12.  
  13. function send_data(){
  14. var g=document.getElementById("_text").value;
  15. winRef.document.getElementById("_child").value=g;
  16. }
  17. </script>
  18. </head>
  19.  
  20. <body>
  21.  
  22. <a href="javascript:void(0);" onclick="open_win();">open window</a><br />
  23. <input type="text" name="_text" id="_text" /><br />
  24.  
  25. <a href="javascript:void(0);" onclick="send_data();">Send data</a>
  26. </body>
  27. </html>
  28.  
Child Window Code:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>Untitled Document</title>
  6. </head>
  7.  
  8. <body>
  9.  
  10. <input type="text" name="_child" id="_child" value=""/>
  11. </body>
  12. </html>
  13.  
cheers !!
Jun 27 '08 #5

acoder
Expert Mod 15k+
P: 16,027
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.
Jun 27 '08 #6

acoder
Expert Mod 15k+
P: 16,027
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.
Jun 27 '08 #7

meenakshia
P: 33
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
Jun 28 '08 #8

acoder
Expert Mod 15k+
P: 16,027
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.
Jun 28 '08 #9

realin
100+
P: 254
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.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2.  
  3.    <html xmlns="http://www.w3.org/1999/xhtml">
  4.  
  5.    <head>
  6.  
  7.    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  8.  
  9.    <title>send data over child window</title>
  10.  
  11.    <script language="javascript" type="text/javascript">
  12.  
  13.    var winRef;
  14.  
  15.    function open_win(){
  16.  
  17.    winRef=window.open("popup.htm");
  18.   send_data();
  19.    }
  20.  
  21.  
  22.  
  23.    function send_data(){
  24.   if(winRef==null){
  25.   alert("Child window doesn't exist");
  26.   return false;
  27.   }
  28.   else{
  29.    var g=document.getElementById("_text").value;
  30.  
  31.    winRef.document.getElementById("_child").value=g;
  32.    }
  33.  
  34.    }
  35.  
  36.    </script>
  37.  
  38.    </head>
  39.  
  40.  
  41.  
  42.    <body>
  43.  
  44.  
  45.  
  46.    <a href="javascript:void(0);" onclick="open_win();">open new child window and send data</a><br />
  47.  
  48.    <input type="text" name="_text" id="_text" /><br />
  49.  
  50.  
  51.  
  52.    <!--<a href="javascript:void(0);" onclick="send_data();">Send data</a>-->
  53.  
  54.    </body>
  55.  
  56.       </html>
  57.  


cheers !!
Jul 3 '08 #10

snehaarora
P: 1
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
Jul 25 '08 #11

acoder
Expert Mod 15k+
P: 16,027
Hi Sheha, welcome to Bytes.

Use window.opener to refer to the parent from the child window.
Jul 29 '08 #12

P: n/a
To open the child window this is the code used in parent window
Expand|Select|Wrap|Line Numbers
  1. <form method=post action='' name=f1>
  2. <table border=0 cellpadding=0 cellspacing=0 width=550> <tr>
  3. <td ><font size=2 face='Verdana'>Your Name</font><input type=text name='p_name' size='8'> 
  4. <a href="javascript:void(0);" NAME="My Window Name" title=" My title here "
  5. onClick=window.open("child3.html","Ratting",
  6. "width=550,height=170,left=150,top=200,toolbar=1,status=1,");>Click here to open the child window</a>
  7.  
  8. </td></tr> </table></form>
  9.  
Inside the Child window code is here
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  
  4. <script langauge="javascript">
  5. function post_value(){
  6. opener.document.f1.p_name.value = document.frm.c_name.value;
  7. self.close();
  8. }
  9. </script>
  10.  
  11. <title>(Type a title for your page here)</title>
  12. </head>
  13.  
  14.  
  15. <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
  16.  
  17. <form name="frm" method=post action=''>
  18. <table border=0 cellpadding=0 cellspacing=0 width=250>
  19.  
  20.  
  21. <tr><td align="center"> Your name<input type="text" name="c_name" size=12 value=test> <input type=button value='Submit' onclick="post_value();">
  22. </td></tr>
  23. </table></form>
  24.  
Oct 25 '10 #13

Post your reply

Sign in to post your reply or Sign up for a free account.