xirukitepe
xirukitepe

Reputation: 1615

Javascript popup selector from Child to Parent Window

Hi I have a problem here. Whenever i try to change the text field value by clicking the button from the child window... it is not working.

Parent window

<html> 
<script language="javascript"> 
function openWindow() { 
  window.open("target.html","_blank","height=200,width=400, status=yes,toolbar=no,menubar=no,location=no") 
} 
</script> 
<body> 
<form name=frm> 
<input id=text1 type=text> 
<input type=button onclick="javascript:openWindow()" value="Open window.."> 
</form> 
</body> 
</html>

Child window which is the target.html

<html> 
<script language="javascript"> 
function changeParent() { 
  window.opener.document.getElementById('text1').value="Value changed.." 
} 
</script> 
<body> 
<form> 
<input type=button onclick="javascript:changeParent()" value="Change opener's textbox's value.."> 
</form> 
</body> 
</html>

What i really want to happen is when I click the button from child window... the child window will be closed and then the text field in a parent window will be changed into "Change opener's textbox's value.." which is the value that Ive chosen from child window..

Upvotes: 1

Views: 1184

Answers (1)

Tosh
Tosh

Reputation: 1857

Javascript is basically restricted to the window. You can't just send values to another window (that would be cool).

There are ways for parent and child windows to communicate to eachother but there are some cross browser issues: http://www.codehappiness.com/post/access-parent-window-from-child-window-or-access-child-window-from-parent-window-using-javascript.aspx

The easiest solution would not be to open a new window but a modal box within the same window. This is nothing more then a div that is styled to appear as a popupbox. The easiest way for a noob to make this is probaply using the jquery ui modal feature.

Good luck!!

Upvotes: 1

Related Questions