Forum Moderators: open

Message Too Old, No Replies

Return from popup

return from popup

         

rsmarsha

3:17 pm on Jul 4, 2007 (gmt 0)

10+ Year Member



I have the following code in my header:

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=600,left = 240,top = 212');");
}
// End -->
</script>

Which causes the following link to open a popup:

<a href="javascript:popUp('http://81.21.79.221:81/adventdata/templates/includes/address_popup.php?e=<?php echo {*customer.e_ChorusAct};?>&c=<?php echo {*customer.customerID};?>&jssCart=<?php echo {*cart.cartID};?>')">Select an Address</a>

The popup runs a db query giving a list of account addresses.

I need to take the return a selected address to the parent window.

This can either be by returning the address as a string and another value which will be the ID, or the ID which can be used to pull the address from the database.

A div containing the address will then be shown and a link to confirm the user wants to use that address.

rsmarsha

4:09 pm on Jul 4, 2007 (gmt 0)

10+ Year Member



My edit time has run out, so will reply instead with the update. :)

I now have the following form in the parent window:

<form name="outputdata">
<input name="ID" size="3">
<textarea name="address" rows="5" cols="30"></textarea>
</form>

The popup has the following code:

<?php $address = ''.$address_r['deliveryCompany'].','.$address_r['deliveryName'].','.$address_r['deliveryAddress1'].','.$address_r['deliveryAddress2'].','.$address_r['deliveryTown'].','.$address_r['deliveryCounty'].','.$address_r['deliveryPostcode'].'';?>
<a href="" onClick="window.opener.document.outputdata.ID.value = '<?php echo $address_r['addressID'];?>';window.opener.document.outputdata.address.value = '<?php echo $address;?>';window.close()" />Select This Address</a>

The above code builds one variable containing the address and then sends that and the ID back to the parent window. This is all good so far.

The problem is, I want the ID to form part of a link in the parent window and the address to be shown inside a span or div tag.

Any ideas on how I do this instead of showing them in a form?

Bernard Marx

4:14 pm on Jul 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In the pop-up, there is a global variable,
opener
, that holds a reference to the global object in the "parent" window. The easist option is to have a script run in the pop-up that either references and updates the div directly:

opener.document.getElementById(..).innerHTML = ..

or passes the text to a function in the parent:

opener.myFunction(text);

--------------------------

By the way

/*
Global vars are members of window
eval is evil
*/
window["page"+id] = window.open(URL, id,
'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,'
+'resizable=1,width=800,height=600,left=240,top=212');

Bernard Marx

6:01 pm on Jul 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry. I managed to tell you things you already know.You posted while I was composing.

It's hard to see what's happening with all that PHP in the way. Could you post a typical example of the relevant pop-up code after PHP processing (in other words, the client-side HTML/script).

rsmarsha

7:51 am on Jul 5, 2007 (gmt 0)

10+ Year Member



Here is a source print of the popup window.

<HTML>
<HEAD>
<TITLE>Child Window</TITLE>

</HEAD>
<body>

<div style="width: 550px; height: 400px; overflow: auto;">
<p>
<a href="" onClick="window.opener.document.ID.value = '1';window.opener.document.outputdata.address.value = '1comp,1name,1add1,deliveryAddress2,deliveryTown,deliveryCounty,deliveryPostcode';window.close()" />Select This Address</a>
<br />

1name,
1add1,
deliveryAddress2,
deliveryTown,
deliveryCounty,
United Kingdom,
deliveryPostcode</p>
<p>
<a href="" onClick="window.opener.document.ID.value = '3';window.opener.document.outputdata.address.value = '3comp,3name,3add1,deliveryAddress2,deliveryTown,deliveryCounty,deliveryPostcode';window.close()" />Select This Address</a>
<br />
3name,
3add1,
deliveryAddress2,
deliveryTown,
deliveryCounty,
United Kingdom,
deliveryPostcode</p>
<p>
<a href="" onClick="window.opener.document.ID.value = '4';window.opener.document.outputdata.address.value = '4,4,4,4,4,4,4';window.close()" />Select This Address</a>

<br />
4,
4,
4,
4,
4,
United Kingdom,
4</p>
<p>
<a href="" onClick="window.opener.document.ID.value = '8';window.opener.document.outputdata.address.value = 'dfgdfg,dfgdfg,dfgdfgwerwer,werwer,werwerwer,werwerwer,werf234';window.close()" />Select This Address</a>
<br />
dfgdfg,
dfgdfgwerwer,
werwer,
werwerwer,
werwerwer,
United Kingdom,
werf234</p>
</body>

</html

I've changed it from pointing to the form, to trying to reference the following code.

<p name="ID" size="3">ID</p>

At the moment the address value isn't pointing back to anything. I actually need the ID to form part of a link and the address to pass as text. I could just pass both back as one value to output as a block of text and have that contain the link itself.

Just need to get it passing back and showing the text at the moment.

Another option would be to write to a hidden form field and somehow echo that form field onto the page with javascript.

Also if none of the above are able to be done, then if i could close the child and redirect the parent to a given link when clicking in the child window. That would be good also. :)

rsmarsha

8:33 am on Jul 5, 2007 (gmt 0)

10+ Year Member



I managed to get the child window to close and redirect the parent. Also think i'm going to change it to populate some text fields we have for enter new and have the passed back address saved when they click enter. :)

Thanks for the help.