I have a web page named A.html, and this web page contains a text box called 'text1', and a button.

When a user clicks the button, a pop up window appears, the name of this pop up window is B.html. B.html has a text box, and its called 'text2', and a button.

The user, when he clicks on the button in A.html, the popup window which is B.html appears. and he/she will type his name in the text box of B.html (popup window). and when he clicks on the button, the popup window must close, and the entered name (in the textbox of B.html), should appear on the textbox (textbox1) of A.html.

hope i made my question clear, i have been googling this for days now, and i haven't come across a solution as yet, how do i code this, can someone post some sample codes to begin?

thank you in advance !

There is a lot of ways you can do that, one of them is:

<html>
	<head>
		<title>JavaScript Window Open/Close Example </title>
	</head>

	<script type="text/javascript">
	   
		var my_window;
	   
		function popuponclick()
		{
			my_window = window.open("",	"mywindow","status=1,width=350,height=150"); // Open window
	 
			if (my_window.opener == null) // Set opener window of the child for compatibility issues
				my_window.opener = self;
	 
			my_window.document.write // Insert content in the child (so i don't have to create an b.html)
			(
				'<input type="text" id="my_window_text" value="" />' +
				'<a href="javascript: opener.updateAndClose();">OK</a>'
			);
		}
	 
		function updateAndClose()
		{
			document.getElementById("my_text").value = my_window.document.getElementById("my_window_text").value; // Set the parent window text input with the child window text input value
			my_window.close(); // close child window
		}
		
	</script>
	
	<body>
		  <a href="javascript: popuponclick()">Open Popup Window</a>
		  
		  <br/>
		  
		  <input type="text" id="my_text" value="" readonly />
		  
	</body>

</html>

Base example from: http://www.javascript-coder.com/

Hope it helps, and if it does, please set it as an answer.

commented: Was googling this for weeks, and i finally found it. +0

There is a lot of ways you can do that, one of them is:

<html>
	<head>
		<title>JavaScript Window Open/Close Example </title>
	</head>

	<script type="text/javascript">
	   
		var my_window;
	   
		function popuponclick()
		{
			my_window = window.open("",	"mywindow","status=1,width=350,height=150"); // Open window
	 
			if (my_window.opener == null) // Set opener window of the child for compatibility issues
				my_window.opener = self;
	 
			my_window.document.write // Insert content in the child (so i don't have to create an b.html)
			(
				'<input type="text" id="my_window_text" value="" />' +
				'<a href="javascript: opener.updateAndClose();">OK</a>'
			);
		}
	 
		function updateAndClose()
		{
			document.getElementById("my_text").value = my_window.document.getElementById("my_window_text").value; // Set the parent window text input with the child window text input value
			my_window.close(); // close child window
		}
		
	</script>
	
	<body>
		  <a href="javascript: popuponclick()">Open Popup Window</a>
		  
		  <br/>
		  
		  <input type="text" id="my_text" value="" readonly />
		  
	</body>

</html>

Base example from: http://www.javascript-coder.com/

Hope it helps, and if it does, please set it as an answer.

Hey,

It worked. Thank you very much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.