[Javascript] how do you access a form element from another frame ?

Hakan M. hakan at backbase.com
Tue Dec 16 11:56:04 CST 2003


Err.

David Lovering wrote:
 > The fact that they sometimes try to access the same objects
 > often proves confusing to newbies, so the distinction is
 > an important one.

Can you give me an example of server side ASP/VBScript and client side 
JavaScript accessing the *same* objects?

Chris Tifer wrote:
 > I'm not sure what this means as ASP Objects are server-side.
 > JavaScript object are client-side. Two totally different
 > scenarios here. There is no window object in ASP. Nothing
 > equivalent.  The server doesn't understand cross-frame
 > scripting. It doesn't even care about it.

Right. And the browser doesn't understand ASP/VBScripting (well, IE 
understands VBScript, but that's CLIENT SIDE VBScript). It never even 
gets to the browser, since it's parsed before the server sends the page 
to the client, where the JavaScript starts kicking in.


Hakan

David Lovering wrote:
> Chris' suggestion of fragmenting the object-access layer by layer through
> the object's DOM tree is a good one, as it enables you to test for the
> existence of each before committing code/time to drilling down further.
> 
> I didn't intend to intimate that ASP and Javascript were peers (functionally
> or otherwise), and I was aware of the client/server differences between
> them -- much the same as with PHP (server-side) and Javascript
> (client-side).  If my failure to make this distinguishing difference clear
> at the start confused folks, my apologies.  The fact that they sometimes try
> to access the same objects often proves confusing to newbies, so the
> distinction is an important one.  As far as I'm concerned, ASP is basicly a
> CGI-like handler language (now I'll hear a loud howl from all the ASP-lovers
> out there!), so it is naturally less concerned about the originating page
> structure, and rather more focused on the passed variables/fields and their
> respective values.
> 
> Also, the "short-hand" form of the <document>.<frame>.<form>.<objectname>
> designation MAY sometimes work, but again Chris' method of explicitly
> referencing things by their proper element array designation is not only
> more portable, but relatively bomb-proof (I've only seen one case where it
> doesn't work quite the way I imagine it should -- and that is with entities
> which have exotic layering, which is something Mozilla-esque browsers don't
> handle in quite the same fashion [read: "at all"]).
> 
> The only time that the parent.top.frames["frameName"] syntax may NOT work is
> when you are accessing something in a child-window from a parent window, or
> vice-versa.  This is for obvious reasons, and can be dealt with relatively
> easily with "window.opener" or some other equivalent work-around.  However,
> this is a moot issue if everything is actually inside the same originating
> window.  The only reason I included the "window" prefix was to put in a
> place-holder to handle possible issues of cross-window variable translation,
> which is where most of my earlier-cited "failures" happened.
> 
> Thanks again to Chris, for slapping a bandaid on my earlier slap-dash
> remarks.  Yay, Chris!
> 
> -- Dave Lovering
> 
> ----- Original Message ----- 
> From: "Chris Tifer" <christ at saeweb.com>
> To: "[JavaScript List]" <javascript at LaTech.edu>
> Sent: Tuesday, December 16, 2003 7:09 AM
> Subject: Re: [Javascript] how do you access a form element from another
> frame ?
> 
> 
> 
>>>Well, the answer (unfortunately) depends a little on which browser you
> 
> are
> 
>>>using.  For example, for IE6+ derivatives, the following should work --
>>>
>>>var yellowTextArea =
>>>window.parent.top.document.frameYellow.document.frm1.textArea1.value;
>>
>>It really shouldn't matter which browser is in use. As long as they a)
>>support frames and b) have JavaScript enabled you should always be able to
>>target another frame by using the following syntax:
>>
>>parent.top.frames["frameName"]
>>
>>So set that as a reference to a frame by doing:
>>
>>var objFrame = parent.top.frames["frameName"]
>>
>>Then if you want to reach a form on that page you do:
>>
>>var objForm = objFrame.forms["formName"]
>>
>>And if you want a handle to the element in question, you can:
>>
>>var objEl = objForm.elements["elementName"]
>>
>>Now you have 3 separate objects you can reference easily enough. If you
> 
> want
> 
>>to target more than one element, then you work off of your objForm object.
>>
>>
>>
>>
>>>Also, I've heard my ASP buddies mention that asp code doesn't
> 
> necessarily
> 
>>>follow exactly the same OOL heirarchy as Javascript (which is a very
>>>imperfect OOL, as far that goes), so don't expect the exact same
> 
> reference
> 
>>>schema to work the same in both Javascript and ASP.  Sorry.
>>
>>
>>I'm not sure what this means as ASP Objects are server-side. JavaScript
>>object are client-side. Two totally different scenarios here. There is no
>>window object in ASP. Nothing equivalent.  The server doesn't understand
>>cross-frame scripting. It doesn't even care about it.
>>
>>Chris Tifer
>>
>>_______________________________________________
>>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