<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2650.12">
<TITLE>RE: [Javascript] Popup window stumper</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>If I understood well, you create a popup window from the main window and set</FONT>
<BR><FONT SIZE=2>the main window var newWind with the handler of the popup. And in the popup,</FONT>
<BR><FONT SIZE=2>you want to use this handler to set a popup declared var called theUser.</FONT>
<BR><FONT SIZE=2>So it's normal it doesn't work because vars only exists under their window.</FONT>
<BR><FONT SIZE=2>You can get your newWind var from the popup with a syntax such</FONT>
<BR><FONT SIZE=2>window.opener.newWind....</FONT>
<BR><FONT SIZE=2>or better</FONT>
<BR><FONT SIZE=2>document.....</FONT>
<BR><FONT SIZE=2>because theUser is declared in the popup so it can access directly the form.</FONT>
<BR><FONT SIZE=2>another solution is to give the popup a name as you create it </FONT>
<BR><FONT SIZE=2>(ie newWind = open("myurl","mynewwind"...)</FONT>
<BR><FONT SIZE=2>and in the popup re-create it with the same name</FONT>
<BR><FONT SIZE=2>newWind = open("","mynewwind");</FONT>
<BR><FONT SIZE=2>and, as it already exists, you'll get a handle on the previously created window.</FONT>
</P>
<P><FONT SIZE=2>but if you want in the popup to access the from in the popup, </FONT>
<BR><FONT SIZE=2>use directly document.</FONT>
</P>
<P><FONT SIZE=2>for the alert messages while errors occurs, it often happens that</FONT>
<BR><FONT SIZE=2>the little icon is set ( in the left bottom corner of IE status bar )</FONT>
<BR><FONT SIZE=2>but the window doesn't appear.</FONT>
<BR><FONT SIZE=2>In a popup you may not have this status bar, so you don't see there was an error.</FONT>
</P>
<P><FONT SIZE=2>-----Message d'origine-----</FONT>
<BR><FONT SIZE=2>De : Terrence Donnelly [<A HREF="mailto:pag000@mail.connect.more.net">mailto:pag000@mail.connect.more.net</A>]</FONT>
<BR><FONT SIZE=2>Envoyé : samedi 15 décembre 2001 19:15</FONT>
<BR><FONT SIZE=2>À : javascript@LaTech.edu</FONT>
<BR><FONT SIZE=2>Objet : [Javascript] Popup window stumper</FONT>
</P>
<BR>
<P><FONT SIZE=2>Could somebody tell me why the following code doesn't work. This file</FONT>
<BR><FONT SIZE=2>is included as a .js file in the head of the main document. A simple</FONT>
<BR><FONT SIZE=2>click on a link calls function gologit. This function correctly</FONT>
<BR><FONT SIZE=2>makes a new window and displays the form and image in it, but clicking</FONT>
<BR><FONT SIZE=2>on the "Log In" button does nothing at all. I'm assuming I have</FONT>
<BR><FONT SIZE=2>some sort of reference problem and/or confusion between the</FONT>
<BR><FONT SIZE=2>parent and child windows, but I am stumped!</FONT>
</P>
<P><FONT SIZE=2>Thanks in advance. </FONT>
</P>
<P><FONT SIZE=2>*******************************************************************************</FONT>
</P>
<P><FONT SIZE=2>// golofile.js - opens a login window</FONT>
<BR><FONT SIZE=2>// adapted from</FONT>
<BR><FONT SIZE=2>// The Javascript Source!! <A HREF="http://javascript.internet.com" TARGET="_blank">http://javascript.internet.com</A></FONT>
<BR><FONT SIZE=2>var newWind</FONT>
<BR><FONT SIZE=2>function gologit() {</FONT>
<BR> <FONT SIZE=2>if (!newWind || newWind.closed) {</FONT>
<BR><FONT SIZE=2> newWind = window.open("", "", "HEIGHT=300, WIDTH=250")</FONT>
<BR> <FONT SIZE=2>if (!newWind.opener) {</FONT>
<BR> <FONT SIZE=2>newWind.opener = window</FONT>
<BR> <FONT SIZE=2>}</FONT>
<BR> <FONT SIZE=2>var newContent = "<HTML><HEAD><TITLE>Grolier Online Log-In</TITLE>"</FONT>
</P>
<P> <FONT SIZE=2>newContent += "<SCRIPT LANGUAGE='JavaScript'>"</FONT>
<BR> <FONT SIZE=2>newContent += "function TryItOut() {"</FONT>
<BR> <FONT SIZE=2>newContent += "var theUser = newWind.document.logform.userbox.value;"</FONT>
<BR> <FONT SIZE=2>newContent += "theUser = theUser.toLowerCase;"</FONT>
<BR> <FONT SIZE=2>newContent += "var thePassword = newWind.document.logform.passbox.value;"</FONT>
<BR> <FONT SIZE=2>newContent += "var theUserLength = theUser.length-1;"</FONT>
<BR> <FONT SIZE=2>newContent += "var theUserFront = theUser.charAt(0);"</FONT>
<BR> <FONT SIZE=2>newContent += "var theUserBack = theUser.charAt(theUserLength);"</FONT>
<BR> <FONT SIZE=2>newContent += "var theFile = theUserFront + thePassword + theUserBack+</FONT>
<BR><FONT SIZE=2>'.htm';"</FONT>
<BR> <FONT SIZE=2>newContent += "alert(theFile);"</FONT>
<BR> <FONT SIZE=2>newContent += "OpenIt(theFile);"</FONT>
<BR> <FONT SIZE=2>newContent += "window.close(newWind.opener)"</FONT>
<BR> <FONT SIZE=2>newContent += "}"</FONT>
</P>
<P> <FONT SIZE=2>newContent += "function OpenIt(theFile) {"</FONT>
<BR> <FONT SIZE=2>newContent += "var root;"</FONT>
<BR> <FONT SIZE=2>newContent += "if (opener.closed) {"</FONT>
<BR> <FONT SIZE=2>newContent += "root = window.open('','');"</FONT>
<BR> <FONT SIZE=2>newContent += "root.location.href = theFile;"</FONT>
<BR> <FONT SIZE=2>newContent += "} else {"</FONT>
<BR> <FONT SIZE=2>newContent += "opener.location.href = theFile"</FONT>
<BR> <FONT SIZE=2>newContent += "}"</FONT>
<BR> <FONT SIZE=2>newContent += "}"</FONT>
</P>
<BR>
<P> <FONT SIZE=2>newContent += "</SCRIPT></HEAD>"</FONT>
</P>
<P> <FONT SIZE=2>newContent += "<BODY><CENTER><IMG SRC='grolog3.gif'><P>Please enter your</FONT>
<BR><FONT SIZE=2>Username and Password<P>"</FONT>
<BR> <FONT SIZE=2>newContent += "<FORM NAME='logform'>"</FONT>
<BR> <FONT SIZE=2>newContent += "Login Name:&nbsp;<INPUT TYPE='text' NAME='userbox' VALUE=''</FONT>
<BR><FONT SIZE=2>SIZE=10><br>"</FONT>
<BR> <FONT SIZE=2>newContent += "Password:&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE='password'</FONT>
<BR><FONT SIZE=2>NAME='passbox' VALUE='' SIZE=10><P>"</FONT>
<BR> <FONT SIZE=2>newContent += "<INPUT TYPE='button' NAME='button' VALUE='Log In'</FONT>
<BR><FONT SIZE=2>ONCLICK='newWind.document.TryItOut()'></FORM>"</FONT>
</P>
<P> <FONT SIZE=2>newContent += "</CENTER></BODY></HTML>"</FONT>
<BR> <FONT SIZE=2>newWind.document.write(newContent)</FONT>
<BR> <FONT SIZE=2>newWind.document.close()</FONT>
<BR> <FONT SIZE=2>} else {</FONT>
<BR> <FONT SIZE=2>newWind.focus()</FONT>
<BR> <FONT SIZE=2>}</FONT>
<BR><FONT SIZE=2>}</FONT>
</P>
<P><FONT SIZE=2>****************************************************************************</FONT>
<BR><FONT SIZE=2>*******</FONT>
</P>
<BR>
<P><FONT SIZE=2>-- Terry Donnelly</FONT>
</P>
<P><FONT SIZE=2>_______________________________________________</FONT>
<BR><FONT SIZE=2>Javascript mailing list</FONT>
<BR><FONT SIZE=2>Javascript@LaTech.edu</FONT>
<BR><FONT SIZE=2><A HREF="https://lists.LaTech.edu/mailman/listinfo/javascript" TARGET="_blank">https://lists.LaTech.edu/mailman/listinfo/javascript</A></FONT>
</P>
</BODY>
</HTML>