Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2007
    Location
    Norway
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Transfer data from pop-up window to text field in another window

    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.

    Code:
    <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:

    PHP 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

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,773
    Thanks
    19
    Thanked 155 Times in 146 Posts
    you need to reference the parent window and send the URL like so:

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

    Code:
    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();" />
    Last edited by chump2877; 02-04-2007 at 09:01 PM.
    Regards, R.J.

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

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    New Coder
    Join Date
    Feb 2007
    Location
    Norway
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot

    The uploader now works like a charm!

    Wombat


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •