Subscribe For Free Updates!

We'll not spam mate! We promise.

Jun 16, 2013

Javascript popup window to return value to parent window

Javascript popup window to return value to parent window:

 We can pass the values to child window to parent window by using javascript. These passing methodology working with html tags and javascript functions.

The javascript popup window is used to get the external value like select the region from map etc.

Follow the below html programs to pass the value from javascript popup window..

parent.html :

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Opener</title>
<script type='text/javascript'>
function valideopenerform(){
var popy= window.open('popup.html','popup_form','location=no,menubar=no,status=no,top=50%,left=50%,height=550,width=750')
}
</script>
</head>

<body>
<form name='form1' id='form1' >
<input type='text' id='text1' name='text1' />
<input type='button' value='go' onclick='valideopenerform()' />
</form>

</body>

</html> 

 In this first html valideopenerform() is i used. in this function i called the second html for open as a popup window. and createone text field with the id "text1". i '' return the value to this text field from popup window.

popup.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Opener</title>
<script type='text/javascript'>
function validepopupform(){
window.opener.document.form1.text1.value=document.form2.text2.value;
self.close();
}
</script>

</head>

<body>
<form id='form2' name='form2' >
<input type='text' id='text2' name='text2' />
<input type='button' value='go' onclick='validepopupform()' />
</form>

</body>


</html> 


 In this second html i used validepopupform() to return the value to parent window text field by using text field id(text1).

Now the value passed to the parent window text field.


TechniqZone Socializer Widget
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

3 comments:

  1. Doesn't work: Uncaught SecurityError: Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.

    ReplyDelete