Forum Moderators: open

Message Too Old, No Replies

Javascript function working fine on one page but not the other

window.opener.document.forms[0].frmCategoryID

         

ASPhopeful

9:57 am on Sep 24, 2004 (gmt 0)

10+ Year Member



Hi All,

I have a pop-up window that populates the forum below. On my uploads.aspx page I have a form textbox called frmCategoryID. The popup called seecategories.aspx uses the following code to populate the field.

function SelectCat(categorycode) {
var txtarea = window.opener.document.forms[0].frmCategoryID;
txtarea.value = categorycode;
txtarea.focus();
self.close();
}

I have another page called default.aspx which also has a form textbox called frmCategoryID which is populated by the same seecategories.aspx page.

However, I get an error when I click to populate the default.aspx page. The error is:

'undefined' is null or not an object

Can someone please help.
Many Thanks
Helen.

Rambo Tribble

3:09 pm on Sep 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is it possible that on the second page the form in question is not the first form (form[0]) on the page?

ASPhopeful

3:57 pm on Sep 24, 2004 (gmt 0)

10+ Year Member



I've thought about that. I did view source on the page and searched for "<form". This only appeared once, so this leads me to believe there is only one form (I wasn't sure due to ASP.net's clients side script).

I thought about nameing the form to "frmflipchart" and changing the javascript to read "window.opener.document.frmflipchart.frmCategoryID;" but this produces the error:

'window.opener.document.frmflipchart.frmCategoryID' is null or not an object

Helen.

Rambo Tribble

1:57 am on Sep 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Clearly, something in the object reference chain is hinckey in the second case. Let's try something just to get our bearings. Give the form element an id (something different than the name attribute's value, like "elId", for example) and see if you can reference it with just opener.getElementById("elId"). That should tell us if we are even in the right ballpark.

By the way, names and ids aren't getting interchanged, by any chance?

Rambo Tribble

1:30 pm on Sep 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Excuse me, opener.document.getElementById("elId");

ASPhopeful

7:14 am on Sep 27, 2004 (gmt 0)

10+ Year Member



Hi Rambo,

I've changed the id attribute of the textbox to elID. It was frmCategoryID as I was already using id instead of name.

<asp:textbox id="elID" text='<%# Container.DataItem( "CategoryID" ) %>' runat="server" size="4" />
(
<a href="#" onClick="NewWin=window.open('seecategories.aspx', 'showwindow', 'toolbar=no,scrollbars=yes,status=no,width=500,height=350');">
see categories
</a>
)

I have changed the javascript to populate the field and it now reads

function SelectCat(categorycode) {
var txtarea = window.opener.document.getElementById("elId");
txtarea.value = categorycode;
txtarea.focus();
self.close();
}

However, I am now getting the "'null' is null or not an object" error message.

Thanks
Helen

ASPhopeful

7:37 am on Sep 27, 2004 (gmt 0)

10+ Year Member



I've just copied and pasted the form field form the working page to the broken page. I'm still getting the "'undefined' is null or not an object" error.

It must be the form, however, a certain for "<form" only produces one result in the source file so it must be forms[0].

Helen