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.

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();

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>

Thanks a lot for the help, guys! I got it to work :slight_smile:

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);

?>