javascript updating grand parent window

I have a situation where I want to in some cases update a field in the parent window and in some cases update a field in the grand parent window. How would I do this?

I have done opener.document.form1.FIELD.value='newvalue'.

How can I do first.opener.document.form1.FIELD.value='newvalue'

Thanks
troyd1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ellandrdCommented:
explain what you mean by grand parent window??

cheers
sean
0
justinbilligCommented:
like you have your main page, that opens a window, that page opens a window

it would be


window.opener.opener.document.form1.FIELD.value - 'newvalue'
0
ZvonkoSystems architectCommented:
Normaly like this:

opener.opener.document.form1.myField.value='newvalue';

But for sure is some of the opener references destroyed bu window reloads.
So my proposal is to give the grandparent window a window name.
Anywere in the gradndparent window do have this line:
<script>
window.name="theGrandParent";
</script>

After that window has a name you can reference to that window from any other window.
To get access to that gradnparent window you can call it like this from realy any window:
<script>
var gp = window.open("","theGrandParent", "top=9000,left=9000,height=100,width=100");
gp.document.form1.myField.value='newvalue';
</script>

Check it.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ellandrdCommented:
try this:

this code opens a window and then opens an popup window (you can change it to open another window for your example..)

<html>
<head>
<script language="javascript">
<!--
var ls_value = 0;
function call() {
     newWin =window.open("childwnd.html", 'TheNewWin', 'height=500, width=700, top=180, left=180,fullscreen=no, scrollbars=yes, resizable=yes, menubar=yes, toolbar=yes, location=yes, directories=yes, status=yes');
}

function getValue() {
     document.write("Value is : " + ls_value);
}
//-->
</script>
</head>
<body onload="call();">
<a href="#" onClick="getValue();">Value from pop window</a>
</body>
</html>


<###### HTML code for childwnd.html ######>
<html>
<head>
<script language="javascript">
<!--
function call_return() {
     //var ls_text = document.frm_child.text1.value
     var ls_text = document.frm_child.t1.value;


     self.opener.ls_value = ls_text
     self.close();
}
//-->
</script>
</head>
<body>
<form name ="frm_child">
<input type="text" name="t1" size="20">
<input type="button" value="Submit" name="btn1" onClick ="call_return();">
</body>
</form>
</html>

sean
0
troyd1Author Commented:
I think what I am proposing is not possible, but I like the suggestions. I will try to explain further:
main window is unnamed, but we will call it A. B has code that updates a form field in A. A will always be the root window.
B can be opened by A or B can be opened by C which was opened by A.

ex.
A > B
A > C > B

I want to generically tell B to update A without giving A a name. Somehow saying root.opener.document.form1.ABC.value = whatever.

I think zvonko's solution is the best, but not exactly what I was asking.

Thanks, Troy
0
ZvonkoSystems architectCommented:
The window A can assign a name to itself and pass it to children and they pass them to grandchildren.
0
troyd1Author Commented:
I guess that I am asking if you can reference the root window without giving it a name.
0
ZvonkoSystems architectCommented:
The root window can be referenced only in a frameset as _top or in DOM as top
Otherwise you cannot list all top windows and select one you like to use.
And why do you like to avoid giving the window a name?
Its such easy like this:
<script>
window.name = "myTopWindow";
</script>

0
ZvonkoSystems architectCommented:
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.