Jump to content

passing info from popup to a parent window


Lodius2000

Recommended Posts

first let me say, I know very little about javascript, i work in php. regardless

 

I have a popup with a file upload on it, when the file is uploaded it performs a mysql query which generates a sequential id number for that file, I would like to transfer that id number to a text field on the parent window and then add a comma after the image,(so i want the text field to look like: 1,2,3,4,5 ... but have no idea how.

 

a few things that I think would be needed are this, the ID number on the popup is a php variable called $img_id, the form on the parent page's form is called 'entry' and the text field that $img_id would go to is called 'images'

 

thanks for any help you can provide

i am unsure if this works in your situation, but you could try

 

parent.<function>.

 

example:

in the pop-up call a function in the parent window by going

<script>

    parent.callFunction(var1, var2, ....);

</script>

 

and obviously that function will have to exist in the parent. When calling the popup you might have to give it a parent id (not 100% sure as i said)

Create a separate page with your parameter and put it for the value of your text field, ex:


 

Then call a separate function with javascript that creates a pop up window with that page and $_GET the vars via HTTP.  There are plenty of examples online but you should pass it like this:

 

$url = "../page_to_call?img_id=". $img_id . "";

 

Sorry if my code is messy I did this quickly, but I hope it helps you.

Pop up page:

...
<script type="text/javascript">
var ids = window.opener.getElementById('ids').value;
if (ids.length==0){
  ids = '<?php echo $img_id; ?>';
}
else{
  ids = ids+',<?php echo $img_id; ?>';
}
window.opener.getElementById('ids').value = ids;
</script>
...

 

Parent page:

...
<input type="text" name="images" id="ids" value="">
...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.