views:

103

answers:

4

Im familiar with accessing parent windows like this:

window.parent.document.getElementById("ad_nr")

But what if I want to access a child window from a parent? (iframe for example) and then set a hidden input in there to some value created in the parent window, how is this done?

Probably easy but I have missed it, so Im asking you guys!

Thanks

+2  A: 

You can use the window.frames collection.

For example:

window.frames[index].document.getElementById('myInputName').value = someValue;
SLaks
A: 
frames["FRAME_NAME_HERE"].document.getElementById("HiddenField1").value = "Whatever";

Note: the document in the iframe must reside on the same domain as the parent. There is no getting around this restriction.

Josh Stodola
A: 

You can use the window.frames array to access child frames. Example:

window.frames[0].document.getElementById('myElement')
windyjonas
A: 

Just access the frames collection and use the document in the usual way. For example:

window.frames['loader_frame'].document.getElementById("ad_nr")
Sergi