[Javascript] detecting a frame with a field

Matt Barton javascript at mattbarton.org
Fri Oct 15 10:54:59 CDT 2004


The return value of getElementsByName() is a collection of objects, so 
you'll need to treat it a little differently.  Even if there's only one 
object in the collection, you still need to treat it like a collection.

If you can say with 100% certainty that it will only return one object 
then you'd do this:

// ---------
myvar = aElements[0].value;
// ---------

Matt

Terry Riegel wrote:

> Another Question,
> 
> How do I assign the contents of the field to a variable. I tried
> 
> myvar=aElements.value
> 
> This placed undefined in myvar.
> 
> 
> Terry Riegel
> 
> Put Your TimeClock on the Web
> http://www.punchedin.com
> On Oct 15, 2004, at 5:05 AM, Matt Barton wrote:
> 
>     Morning Terry,
> 
>     You'll have difficulties if the documents in the two frames are
>     served from different domains - you'll get "Access Denied" errors in
>     javascript when trying to access the right-hand frame.
> 
>     I know that you haven't said that they are below, but when you said
>     that the right hand frame wasn't under your control, I thought that
>     might have been one of the possibilities.
> 
>     Assuming that the two documents are from the same domain however, I
>     suppose you could use the setInterval () method of the left hand
>     window to call a function every so often which checks the right hand
>     frame. The function could use the getElementsByName method of the
>     document in the right hand window.
> 
>     Something like:
> 
>     // ------------
>     function fCheckFrame () {
>     oRightHandDocument = parent.idOfRightHandFrame.document;
>     aElements = oRightHandDocument.getElementsByName ('CO_USERNAME');
>     if (aElements.length > 0) {
>     document.forms[0].submit ();
>     }
>     }
> 
>     window.setInterval (fCheckFrame, 100);
>     // -------------
> 
>     You would need to know the ID and/or name of the right hand frame,
>     but you'll have control over that won't you? Also you'd need to
>     customise the reference to your form - I just used form[0] to
>     reference the first (only) form in the document in my test case.
>     I've tested this in IE6/Win and Firefox and both are OK.
> 
>     Hope this helps a little. I'd be interested to see if anyones got a
>     better method of triggering the check of the right hand frame, as I
>     don't particularly like window.setInterval - it strikes me as (in
>     this instance) a little inelegant.
> 
>     Ta ta,
> 
>     Matt
> 
>     Terry Riegel wrote:
> 
>         Hello All,
>         I have set up a 2 frame page. The left frame is fully under my
>         control, the right frame is not.
>         +--+------+
>         | | |
>         | | |
>         | | |
>         +--+------+
>         I want the left frame to watch the right frame until it contains
>         a form with a text field named CO_USERNAME
>         The Right frame (I can't control its contents) will look like
>         below.
>         <body>
>         <form method=post action=http://www.page.com>
>         ...
>         <input type=text name=CO_USERNAME size=30 maxlength=30
>         value="Visitor5">
>         ...
>         </form>
>         </body>
>         When the left frame sees a text field labeled CO_USERNAME it
>         will trigger a page load.
>         Can this be done?
>         Terry
>         _______________________________________________
>         Javascript mailing list
>         Javascript at LaTech.edu
>         https://lists.LaTech.edu/mailman/listinfo/javascript
> 
>     _______________________________________________
>     Javascript mailing list
>     Javascript at LaTech.edu
>     https://lists.LaTech.edu/mailman/listinfo/javascript
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript



More information about the Javascript mailing list