...

View Full Version : Transfer data from pop-up window to text field in another window



Wombat
02-04-2007, 07:48 PM
Hi all

This is my first post here and my JavaScript knowledge is limited, so please bear with me.

I have PHP guestbook that allows the users to upload an image. The upload script opens in a pop-up window. When the picture is uploaded successfully a preview of the image appears along with a link to the image (still in the pop-up).

Is it possible to create a "Paste image" button that pastes the image link from the pop-up into a text field in the "Add guestbook entry" page with JavaScript? I also want the pop-up to close when the link is inserted in the text field. Can I use "onclick="opener.insert" something?

Here is the text field from the "Add guestbook entry" page.


<strong>Image link:</strong><br>
<input type=\"text\" name=\"picture\" id=\"ImgUrl\" value=\"$_POST[picture]\" size=\"30\">

Here is the code from the php page that needs the JS code:


if ( strstr($filetype, "gif") )

{ //Shows the picture
echo "<div align=\"center\"><h3>Preview:</h3></div>";
echo "<div align=\"center\"> <img src='$filename' height='200'</div>";
}


echo "<ul>\n\t<li>Filename: http://www.mysite./$filename\n</li><br>";
echo "\n</ul>";
echo "<form><input type=\"button\" name=\"Button\" value=\"Paste image\"></form>";


Thanks in advance for any answers!

Thanks,
Wombat

chump2877
02-04-2007, 08:52 PM
you need to reference the parent window and send the URL like so:


<input type="button" value="Paste Image URL" onclick="opener.document.formName.textboxName.value = 'yoursite.com';" />Then close the popup with:


window.close();
Edit: so the code is like this put together:


<input type="button" value="Paste Image URL" onclick="opener.document.formName.textboxName.value = 'yoursite.com/image.jpg'; window.close();" />

Wombat
02-04-2007, 10:52 PM
Thanks a lot :)

The uploader now works like a charm!

Wombat



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum