[Javascript] Accessing atributes - window.opener

Shawn Milo ShawnMilo at runbox.com
Tue Sep 28 14:31:45 CDT 2004


Just to add my 2¢, here's a sample of something I did recently.
I know it's a day late and a dollar short (98¢ short?), but I just
wondered if it might help someone.

This snippet is a piece of ASP code (vbScript), which writes a
bunch of links from an SQL query.

Shawn

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Begin Code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


If rsForm.EOF Then
   toPage "<p>There were no results.  Please try again.</p>"
Else

   regEx.Pattern = "^#(\d{3}).*$"
   storeNum = regEx.Replace(rsForm("deptdesc"), "$1")
   toPage "<table>"
   Do Until rsForm.EOF
      toPage "<tr>"
      toPage "<td><a href=""#"" onclick=""opener.window.document.forms['thisForm'].elements['psid'].value = '" & rsForm("psid") & "';opener.window.document.forms['thisForm'].elements['snum'].value = '" & storeNum & "';opener.window.document.forms['thisForm'].elements['jtitle'].value = '" & rsForm("jtitle") & "';opener.window.document.forms['thisForm'].elements['uname'].value = '" & rsForm("lname") & ", " & rsForm("fname") & "';window.close();"">" & rsForm("lname") & ", " & rsForm("fname") & "</a></td>"
      toPage "<td>"  & rsForm("deptdesc") & "</td>"
      toPage "<td>"  & rsForm("jtitle") & "</td>"
      toPage "</tr>"
      rsForm.MoveNext
   Loop
   toPage "</table>"
End If

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
End Code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

> Here I go again...
> 
> Now, I've put an input text field on the first page.
> With a click in OK, on the opened window, I want to
> put a value on this input text field. I tried several
> things, like window.opener.document...,
> self.opener.document, and so on. None of these worked.
> 
> Does anyone know what could be wrong? Thanks.
> 
> main.html (calls the pop-up window) :
> 
> <HTML>
> <HEAD>
>   <script src="window.js"></script>
> </HEAD>
> 
> <BODY onfocus="javascript:checkForDialog();"
> id="main"> 
>   <a href="javascript:topwind();">Click</a> to open
> small window.</p>
>   <form id="update">
>     <input type="text" name="code">
>   </form>
> </BODY>
> </HTML>
> 
> 
> button.html (elements of the pop-up window) :
> 
> <HTML>
> <HEAD>
>   <script src="window.js"></script>
> </HEAD>
> 
> <BODY onfocus="javascript:checkForDialog();">
> <FORM id="select">
>   <table cellSpacing="1" cellPadding="2" width="300"
> border="0">
>     <tr>
>       <td colSpan="2">Select option:</td>
>     </tr>
>     <tr>
>       <td></td>
>       <td>&nbsp;</td>
>      </tr>
>     <tr>
>       <td>Letters:&nbsp;</td>
>       <td>
>         <select name="select_l">
>           <option value="Option A">Option A
>           <option value="Option B">Option B
>           <option value="Option C">Option C
>           <option value="Option D">Option D
>         </select>
>       </td>
>     </tr>
>     <tr>
>       <td></td>
>       <td>&nbsp;</td>
>     </tr>
>     <tr>
>       <td colSpan="2">
>         <P align="center">
>           <input type="button" name="but_ok"
> value="OK" onclick="javascript:closeWindow();">&nbsp;
>           <input type="button" name="but_cancel"
> value="Cancel" onclick="">
>         </P>
>       </td>
>     </tr>
>   </table>
> </FORM>
> </BODY>
> </HTML>
> 
> 
> window.js (contains javascript functions) :
> 
> var newWindow;
> 
> function topwind()
> {
>   newWindow =
> window.open('button.html','newWindow','toolbar=no,status=no,width=350,height=200')
> }
> 
> function checkForDialog()
> {
>   if (newWindow && newWindow != null &&
> !newWindow.closed)
>   {
>     newWindow.focus();
>   }
> }
> 
> function closeWindow()
> {
>   self.opener.document.update.code.value = "50";
> //error here
>   //according to mozilla javascript console, this is
> the error:
>   //  Error: self.opener.document.update has no
> properties
>   //  Source: file:///d:/guilherme/java/window.js
>   //  Line: 18
>   self.close();
>   self.opener.newWindow = null;
> }
> 
> 
> 	
> 	
> 		
> _______________________________________________________
> Yahoo! Messenger 6.0 - jogos, emoticons sonoros e muita diversão. Instale agora!
> http://br.download.yahoo.com/messenger/
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
> 
> 



More information about the Javascript mailing list