General Discussions

*HELP* javascript problem – rowanseymour

rowanseymour

Member

Posts: 284
From: Belfast, Northern Ireland
Registered: 02-10-2001
I have 2 html pages. The first one calls window.open() to display the second in a popup window. Then trys to change the value of single text edit in the second pages only form.

The first page is simplified as follows:

<HTML>
<HEAD>
<TITLE>Test Page 1</TITLE>
<SCRIPT LANGUAGE="JavaScript">

function doPopup(url, msg)
{
popup = window.open(url, 'popup', 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes');
popup.document.forms[0].elements[0].value = msg;
}

</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="myForm">
<INPUT TYPE="BUTTON" VALUE="Popup" onClick="doPopup('popup.html', 'Hello')">
</FORM>
</BODY>
</HTML>

The second page...

<HTML>
<HEAD>
<TITLE>Popup</TITLE>
</HEAD>
<BODY>
<FORM NAME="form1" METHOD="post" ACTION="">
<INPUT TYPE="TEXT" NAME="Msg" VALUE="">
</FORM>
</BODY>
</HTML>

Instead of working it throws up a lovely error box saying...

Line: 9
Char: 3
Error: 'popup.document.forms.0.elements' is null or not an object
Code: 0
URL: file//.........

Am I missing something really obvious here??? Please say yes because this part of a huge piece of coursework I have to hand in on Monday

Krylar

Administrator

Posts: 502
From: MD, USA
Registered: 03-05-2001
Hiya,

The problem is in that you're naming the variable that holds the popup window the same as the name you're giving the window.


popup =
window.open(url, 'popup',
'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes');

Note that popup is your new handle to the window, but JavaScript is also being told that the window name it popup. I changed the window name to newpopup and it worked for me.


popup =
window.open(url, 'newpopup',
'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes');

This *did* work in IE, by the way, but IE uses JScript which--strangely--is a bit more forgiving of things such as this. Netscape is more of a stickler for most things...and currently has a number of plain Java issues.

Hope that works for you too!

-Krylar

------------------

[This message has been edited by Krylar (edited May 10, 2001).]

rowanseymour

Member

Posts: 284
From: Belfast, Northern Ireland
Registered: 02-10-2001
Cheers but that hasn't fixed it (IE6b + Win2000) . It's weird - it works a few times then starts throwing up errors. I have found another way to do this though by handing onLoad() in the popup page and then setting the value of the text field, reading from the parent page using the opener handle.

Me thinks window.open() is returning before the form elements are properly initialized. A bug perhaps? In a microsoft product?

Thanks anyway

Krylar

Administrator

Posts: 502
From: MD, USA
Registered: 03-05-2001
hmmmm...kooky. Didn't work for me in Netscape at all and it ran fine in IE. Of course I don't have Win2000 here, so maybe that has something to do with it.

Well, sorry I couldn't help!

-Krylar

------------------