Link to home
Start Free TrialLog in
Avatar of moconn
moconn

asked on

Help with Remote Control Window - 500 pts


Hi Experts,

I am having a problem with javascript remote control..

I have found loads of examples on the web of how to create a remote control to redirect the parent window to a new page
but nothing that does what i need..

Issue:

I have a form (parent window) and a popup (child window). When the popup is opened the user can upload an image I want to populate the path to the image into the relevant field in my parent window when the user closes the child window.

I.e.

Parent Window

Photo:

The photo below is the current photo
xxxxxxxxxxx
xxPHOTOxx
xxxxxxxxxxx
xxxxxxxxxxx

Change Photo   <----- Opens popup


Popup
 ______________________
|_____________________|

Browse | Upload

I.e. Once i've uploaded the file in the popup and its been previewed then the user closes the window
and the the path is passed back to the original window | original window refreshed so the user can see the photo.

PS The upload code is working fine, all i need is to be able to pass the url of the photo back to the original page and refresh the original page.

Thanks

Avatar of Zvonko
Zvonko
Flag of North Macedonia image

The popup can get this access to parent window:
<script>
function setParent(){
  var pImg = opener.document.images;
  var pForm = opener.document.forms[0];
  // now you can set the parent image src by the parent image name:

  pImg.PHOTO.src = "images/theUploaded.jpg";  // img.src
  pForm.imagePath.value = "images/theUploaded.jpg";  // form field value
}

window.onunload = setParent;

</script>



Avatar of moconn
moconn

ASKER


Cheers for your answer,

Just want to clarify a couple of things excuse my complete novice at Javascript..

Currently i'm opening the popup in the parent by using this script between the <head> tag

<SCRIPT LANGUAGE="javascript">
<!--
var newwindow;
function poptastic(url)
{
      newwindow=window.open(url,'name','height=270,width=300');
      if (window.focus) {newwindow.focus()}
}
-->
</SCRIPT>

and this link in within the <body> tag

echo "<a href='javascript:poptastic(\"./upload_photo.php?article_id=$article_id\");'> Change Photo</a><br>";

Questions are:

a. I presume the code above is to be placed within the <head> tag of the popup?
b. Is my popup code in the parent combatible with your code above?
c. How is the updated path [images/theUploaded.jpg] accessible in the parent?
d. Does this code refresh the original parent window?

Thanks...




ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of moconn

ASKER


That did the trick..

Thanks for all your help..
You are welcome.