loosing values once window closes

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

loosing values once window closes

Post 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?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

You have to POST the values yourself. It won't do it for you.
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Post 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.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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?
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Post 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.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Post 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?.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

You shouldn't need to do anything JavaScript-wise in the child window.
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Post 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?
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Post 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:
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Might want to ask in the client side forum. :wink:
Post Reply