Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get value from new window

Status
Not open for further replies.

firehorse24

Programmer
Sep 22, 2006
28
US
Hi everyone,

Hope someone can help with it.

I had a web page in asp. it has a button has event handler. if I click the button, it run a js to open a new window, with 2 input (text) fields and a submit button in there. My question is how do I validate those 2 input fields in popup window and return value back to parent page?

Thanks a lot!

Here is my script:

Code:
<html>
<head>
	<title>Untitled</title>
	<script language="javascript">
	<!-- 
    function makenewwindow()
	{
	 var newWindow = window.open("", "nwindw","width=200, height=300")
	 if (newWindow != null)
	 {
	  var newcontent = "<html><head><title>Sub Window  </title></head>"
	   newcontent += "<body><form name='nwf1' ><input type='button' value='Submit Job'  onclick= 'sbmnw(); return false;'><br>" 
	   newcontent += "<input type='text' name='nwdate1' value='' size='8' maxlength='8' ><br>" 
	   newcontent += "<input type='text' name='nwdate2' value='' size='8' maxlength='8' >" 
	   newcontent += "</form></body></html>"
	  
	  newWindow.document.write(newcontent)
	  newWindow.document.close
	
	 }
		
	}
	function sbmnw()
	{}
	
		// -->
	</script>
</head>


<body>

<form>
<input type="button" Name="newone" value="Create New Window"  onclick = "makenewwindow()">
</form>

</body>
</html>
 
That depends on what you mean by validation.

To get their value, this should work:

Code:
alert(newWindow.document.forms['nwf1'].elements['nwdate1'].value);

That, of course, assumes that either "newWindow" is made global, or you are running this code inside of the "makenewwindow" function.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hi Dan,

Thank for your reply. Sorry I'm not good at Javascript. I tried to put the following code everywhere inside the function makenewwindow. It won't work right. When I click the button in parent's page, it popup right away instead of showing the new window.
Code:
alert(newWindow.document.forms['nwf1'].elements['nwdate1'].value);

What should I do if I want to click the button in the new page and return the value back to the parent page,

Thank you very much!

 
You can run this from the popup to set a global variable in the opener, called 'myVar', with the value:

Code:
opener.myVar = document.forms['nwf1'].elements['nwdate1'].value;

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hi Dan,

I code
Code:
><input type='button' value='Submit Job' onclick= 'sbmnw(); return false;'>
in the popup window. why it doesn't do anything when I click the button? where should I put the function sbmnw()?

thanks you!
 
hi,

I don't know where i should put it. What I'm tring to do is when I click a button in the main page, a new window pops up, which having two input fields (not one field. I know I can use prompt to get one value). then I click the button in the new window. the new window closed and the input value return back to the main page or I can retrieve those input value in the main page. How can I do that please? I appreciate if you have the code.

Thanks a lot!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top