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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PLEASE HELP!! window.opener.document IS NULL

Status
Not open for further replies.

questhaven

Programmer
Mar 28, 2001
81
0
0
US
Help! I am ripping my hair out with this one!

Here's the situation:
I have a full ASP page with a link that launches a pop-up containing a drop down list of items. Upon selecting an item I am posting back to the same pop-up in order to process the selection and customize the results using SQL. Then I am *TRYING* (not very successfully) to post this newly constructed message to a text box on the initial full page. When I do try this I get the message about window.opener.document. being a null object, I understand why this is happening - I am just trying to figure out a way around it. Does anyone know of a way I can save the original window.opener.document value and use that to return to the first ASP page with the new value once the processing has been done?

Any suggestions, ideas or anything else would be SOOOOOOOOOOO greatly appreciated!!!
 
Are you creating the pop-up window with javascript using
window.open("menu.asp", "viewMenu") or with a TARGET attribute in the anchor tag? The first approach defines the window.opener property for the pop-up, don't know about the TARGET approach.

So you submit the form in the pop-up to itself, menu.asp, retrieve some stuff from a database, which you then want to write into a text-box on a form in the first window?

And you have javascript in the pop-up that does something like
Code:
opener.forms[0].textboxToBeFilled.value = "Stuff from database";

And it doesn't work because opener is NULL?
 
YES!!! :) That is exactly what I am trying to do. Do you have any suggestions??
 
are you holding a reference to the popup window in javascript ie.

var popwin

popwin = window.open('popup.asp')

if you dont keep a reference in the parent to the popup window then you cant refer to the parent as opener in the popup window, i think???
 
I believe sjravee has defined a reference to the pop-up window, not to the opener.

What version of IE are you using, I seem to remember an earlier version of IE5 had a bug in setting the opener property.

This works for me in N4.7, N7, and IE6
Code:
<html>
<!-- The first window -->
<head>
	<title>Form With Pop-up Window Menu</title>
</head>

<body>

<form>Model: <input type=&quot;text&quot; name=&quot;textboxToBeFilled&quot;></form>

<a href=&quot;#&quot; onclick='javascript:window.open(&quot;menu.asp&quot;, &quot;viewMenu&quot;, &quot;height=400,width=200&quot;)'>Fill in the blank</a> from a database of VINs.

</body>
</html>

Code:
<!-- The pop-up window -->
<% @ language=&quot;JScript&quot; %>

<!-- #include file=&quot;../connection.asp&quot; -->

<%
//Build option list for vin menu.
var rsGet = Server.createObject(&quot;ADODB.Recordset&quot;); 

rsGet.open(&quot;SELECT vin FROM cars&quot;, conn);

var strOptions = '<option value=&quot;-1&quot;> . . . Select VIN . . . </option>\n';
while( !rsGet.EOF ) {
	
	strOptions += '<option value=&quot;' + rsGet.Fields(&quot;vin&quot;).value + '&quot;>' + rsGet.Fields(&quot;vin&quot;).value + '</option>\n';
	
	rsGet.moveNext();
}


//Fillin the blank if we have a vin.
var vVIN = Request.Form(&quot;vin&quot;).item();
var valueToFill = &quot;&quot;;

if( vVIN != null ){
	rsGet.close();
	rsGet.open((&quot;SELECT model FROM cars WHERE vin = '&quot; + vVIN + &quot;'&quot;), conn);
	if( !rsGet.EOF ){ valueToFill = rsGet.Fields(&quot;model&quot;).value; }
}

//Clean up.
rsGet.close();
rsGet = null;
conn.close();
conn = null;
%>
<html>
<head>
	<title>Vehicle Identification Number</title>
</head>

<body>

<h3>Vehicle Identification Number</h3>

<form method=&quot;post&quot; action=&quot;menu.asp&quot;>
<select name=&quot;vin&quot;>
<%= strOptions %>
</select>
<br>
<input type=&quot;submit&quot;>
</form>

<script>opener.document.forms[0].textboxToBeFilled.value = &quot;<%= valueToFill %>&quot;;</script>

</body>
</html>
 
I'm using IE6. I'm going to try this and let you know. In any case - thanks SO MUCH for taking the time to respond. :):)
 
I'm not sure if this will work, but you could try naming the parent window before opening the popup using this:
Code:
window.name=&quot;parentWindow&quot;;

Then put this above your code in the popup before you try to use window.opener:
Code:
window.opener=window.open('','parentWindow');

Adam
while(woman.width>woman.height && wallet.value>0){beer++;vision.blur()};
 
rac2 - thanks for the idea - but I am afraid it won't work. You see I have one page (let's call it page A) that has to call a pop-up (Page B) that generates a drop down based on database contents (as you have above). My problem is that I need to post these results to another processing page (Page C) (or the same pop-up) so that I can strip some information out of the results of the recordset. Then I have to put that data back into a textarea on Page A.

Does this make sense? Any help would be so appreciated!
 
Oh, the problem metamorphoses. I am sure you will get it right eventually. Best of luck.
 
>> Does this make sense?

I don't think so. It sounds like your problem is that you believe you have to do the server round trip in the popup window and then get the text from there back to the original window.

Instead just post the round trip to the original window using the target attribute of the form in the popup, and then it's response will have the text from the round trip to the server. There will be no need for the popup to communicate with the original window.


-pete
 
dont try and access the openers document from the popup. Instead pass a reference to the form object in the popup window to a function in the opener and call it....

window.opener.GetData(this.form)

in your main page, the opener, addd a function to it called GetData

function GetData(formObj)
{
alert(formObj.elements.length)
}

know you have the form data from the popup in the main page. You can then add the text to your textarea from the GetData method.

Hope this makes sense
 
dont try and access the openers document from the popup. Instead pass a reference to the form object in the popup window to a function in the opener and call it....

window.opener.GetData(this.form)

in your main page, the opener, addd a function to it called GetData

function GetData(formObj)
{
alert(formObj.elements.length)
}

now you have the form data from the popup in the main page. You can then add the text to your textarea from the GetData method.

Hope this makes sense
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top