Page 1 of 1

loosing values once window closes

Posted: Mon Oct 15, 2007 7:36 am
by shivam0101
Iam having a checkbox in a loop

Code: Select all

$str.="
<tr>
   <td><input type='checkbox' name='email_id[]' value=$value></td>
   <td style='Font-Family:verdana;Font-Size:14'>".$contacts['name'][$i]."</td>
   <td style='Font-Family:verdana;Font-Size:14'>".$contacts['email'][$i]."</td>
</tr>";
Javascript

Code: Select all

function refreshParent() {
  window.opener.location.reload();
  window.close();
}
In the main window there is a link, on clicking the link a popup window opens with the above script. I want the values which are selected in checkboxes should be sent to main window and the popup should close.

Everything works fine, but the values are not sent to main window. I tested without closing the popup, It is sent to the main window.

How to send the values and close the popup?

Posted: Mon Oct 15, 2007 7:46 am
by superdezign
You have to POST the values yourself. It won't do it for you.

Posted: Mon Oct 15, 2007 7:55 am
by shivam0101
I am doing that, it was working fine when i tested using

Code: Select all

print_r()
, but after i started to close the popup and refresh the main window, i am not getting any values.

Posted: Mon Oct 15, 2007 8:00 am
by superdezign
Why would you think refreshing a window would keep the values? And at what point are you POSTing the values to the popup?

Posted: Mon Oct 15, 2007 8:06 am
by shivam0101
so, how to send pop up window values to parent window before closing and retain it in main window? I think its sending the values and on refresh its loosing the values...as you have pointed out.

Posted: Mon Oct 15, 2007 8:30 am
by superdezign
From the child to the parent? Well, the parent has access to the child's DOM, which would be how you could get all of the values. Just use the child window's "onclose" event to determine when it's closed and get the data.

Posted: Mon Oct 15, 2007 8:50 am
by shivam0101
are you saying,

in popup:

Code: Select all

function refreshParent() { 
  window.opener.location.reload(); 
  window.close(); 
}
in main window:

i should detect child window is closed.
if yes then get the values of the element needed and populate the main window fields?.

Posted: Mon Oct 15, 2007 9:26 am
by superdezign
You shouldn't need to do anything JavaScript-wise in the child window.

Posted: Mon Oct 15, 2007 10:03 am
by shivam0101
in main window,

Code: Select all

<script language="JavaScript">
function popup()
{
  var popup_window=window.open('contact/index.php');
}

function getMailIds()
{
    var val1 = popup_window.document.forms["form1"].elements["email_id"].value;
	alert(val1);
}

</script>
<body onUnload="getMailIds();">
Nothing has been written in child window. Now, how do i close the child window?

Posted: Fri Oct 19, 2007 3:05 am
by shivam0101
Thanks superdezign.

I solved it by using

Code: Select all

session
.

I still do not know how to solve it using javascript :cry:

Posted: Fri Oct 19, 2007 6:39 am
by Benjamin
Might want to ask in the client side forum. :wink: