SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot thetzfreak's Avatar
    Join Date
    Aug 2004
    Location
    United States
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How To Insert Text From Popup OnClick()

    Hey, I'm new to javascript, and I need some quick help on how to do something.

    I have a form, and one of the text boxes should be a URL to an image. I have a link to popup an image-upload script. On that popup, after they upload the file, they'll have a URL. I don't want to give specific instructions to "Copy paste the URL into the form". I want it so that they'll click a button called "Insert into Form" and it'll automatically close the popup and insert the URL into the text box.

    How do I do this?

    Thank you for the help in advance.

  2. #2
    SitePoint Member
    Join Date
    Jul 2007
    Location
    Silion Valley
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do something like this in the child window:

    // Update parent window.
    window.opener.document.myForm.myUrlField.value = "this url from child";

    // Close child window.
    window.close();
    I've made every mistake and suffered every pain.
    So you don't have to.
    Stuck with JS or AJAX issue? Ask me here.

  3. #3
    SitePoint Member Mupo's Avatar
    Join Date
    Oct 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello try this examples, can be useful

    index.html

    <html>
    <head>
    <title>Parent</title>
    <script>
    var w;
    function open_child()
    {
    w = window.open("winc.html","z","width=600,height=800");
    }
    </script>
    </head>
    <body>
    <input type="text" id="test" />
    <input type="button" onclick="open_child()" value="test"/>
    </body>
    </html>

    winc.html
    <html>
    <head>
    <script>
    function submit_data()
    {
    window.opener.parent.document.getElementById("test").value = document.getElementById("txt").value;
    window.opener.parent.w.close();
    }
    </script>
    </head>
    <body>
    <input type="text" id="txt"/>
    <input type="button" onclick="submit_data()" value="submit"/>
    </body>
    </html>

  4. #4
    SitePoint Zealot thetzfreak's Avatar
    Join Date
    Aug 2004
    Location
    United States
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot for the help, guys! I got it to work

  5. #5
    SitePoint Member
    Join Date
    Jul 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello. I used the code you provided and it worked great. However, I'm trying to make the popup display data dynamically. I've provided my code below, which correctly displays my images/buttons dynamically. But when I click on any button to insert the text into the parent field, all buttons default to the first name in the popup. I would like each button to insert the text of the corresponding image name. Any help would be greatly appreciated. Thanks in advance.

    See link for reference:
    http://ettlinmedia.com/test.html

    <script>
    function submit_data()
    {
    window.opener.parent.document.getElementById("image").value = document.getElementById("file").value;
    window.opener.parent.w.close();
    }
    </script>

    <?php
    $path = "./";
    $dir_handle = @opendir($path) or die("Unable to open folder");

    while (false !== ($file = readdir($dir_handle))) {

    if($file == "test.php")
    continue;
    if($file == ".")
    continue;
    if($file == "..")
    continue;

    echo "<img src='$file' alt='$file' width='100'><input type='button' onclick='submit_data()' id='file' value='$file'/><br />";

    }
    closedir($dir_handle);

    ?>


Bookmarks

Posting Permissions

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