Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need to pass text value from pop up to parent

Status
Not open for further replies.

phillyfino

Programmer
Jan 16, 2003
6
US
Hello,

I'm pretty new to javascript, I needed to pass a text value from a pop up window into the parent window. What I'm doing is actually for an image....a pop up window will contain a list of images, you click on an image and the pop up closes and the image you click on will appear on the parent frame. I just need the image url, which I have on the pop up, now I need to get that url to the parent window when I click the pic. Is there a faster way to do this other than using the opener method? Thanks for your help.
 
Try placing this into the popup window:

function showPic(img)
{
opener.document.images[n].src = img;
}

<a href=&quot;#&quot; onclick=&quot;showPic(document.images['one'].src)&quot;><img src=&quot;1.gif&quot; name=&quot;one&quot;></a>
<a href=&quot;#&quot; onclick=&quot;showPic(document.images['two'].src)&quot;><img src=&quot;2.gif&quot; name=&quot;two&quot;></a>

The script will replace some default image in parent window with another one selected from popup.
 
Thanks for the help starway...I actually should have stated that I need the image that I click on to go to a specific div tag on the parent page (tracked by div id). For example, the following is the code that I have:

function setPic()
{
opener.document.form.getElementById('1_2').value = '/media/content/10/05/1005.jpg';
self.close();
}

I am getting an &quot;object doesn't support this property or method&quot; error, probably due to the getElementById(). What's a simple way to make sure that the picture that I click on gets passed into the correct div tag? I am using similar code in other parts of the program where I deal with text (inserting text depending on div id) so I would like to keep my setPic() functioning in a similar way. Thanks again for your help

 
The error is quite clear: getElementById doesn't have such a property as &quot;value&quot;. Also, after looking at your code, I think that you don't know exactly how to use getElementById.

I always stand for the most simple solution, and in your case it's like I described. Place the default image anywhere on the parent document - in some div as you said, or elsewhere, and try the function I suggested.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top