Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Passing value from a popup window to its parent window

I'm new in javascript and I'm stuck here. Let's say I have a parent window and it has an input field as well as a button that opens a popup window. This popup window contains Images. I just need to copy image URL to that input in the parent window when I click on any image on the popup window. Any help please. Thanks

Edit:

This is my javascript code on the popup window

<script type="text/javascript">
function clicked(address) {
    window.parent.document.getElementById('copy_img').value = address.src;

}
</script>

HTML

<input type="text" name="copy_img" id="copy_img" size="133" />
<img border="0" onclick="clicked(this)" src="images/1.jpg" width="135" height="46">
<img border="0" onclick="clicked(this)" src="images/2.jpg" width="128" height="48">
<img border="0" onclick="clicked(this)" src="images/3.jpg" width="305" height="44">

Parent Window HTML Code

<input type="text" name="copy_img" id="copy_img" />

I Just Can't get it to work

like image 844
user2044626 Avatar asked Feb 27 '14 17:02

user2044626


People also ask

How do I pass a value from child window to parent window?

From a child window or a small window once opened, we can transfer any user entered value to main or parent window by using JavaScript. You can see the demo of this here. Here the parent window is known as opener. So the value we enter in a child window we can pass to main by using opener.

How do you pass a parameter in a popup window?

Click the Open / Swap radio button. Under Window, use the dropdown list to select the path to your Popup Window (i.e.,Popup_Param_Test). Check the Pass Parameters check box, and click the Add icon to add a parameter. Click the new row under Parameter Name and a dropdown list will appear.

How do I return a value from a Windows Open?

Typically the onclick event on the "Yes" or "Ok" button in the modal dialog looks like this: window. returnValue = true; window. close();

What is the JavaScript command for a popup window?

The syntax to open a popup is: window. open(url, name, params) : url. An URL to load into the new window.


1 Answers

I finally figured it out Use window.opener

window.opener.document.getElementById('archiveimages').value = address.src;
like image 112
user2044626 Avatar answered Sep 24 '22 12:09

user2044626