?
Solved

javascript updating grand parent window

Posted on 2004-11-12
9
Medium Priority
?
629 Views
Last Modified: 2008-03-17
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
0
Comment
Question by:troyd1
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 16

Expert Comment

by:ellandrd
ID: 12567438
explain what you mean by grand parent window??

cheers
sean
0
 
LVL 15

Expert Comment

by:justinbillig
ID: 12567469
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
 
LVL 63

Accepted Solution

by:
Zvonko earned 1000 total points
ID: 12567537
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 16

Expert Comment

by:ellandrd
ID: 12567538
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
 

Author Comment

by:troyd1
ID: 12624743
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
 
LVL 63

Expert Comment

by:Zvonko
ID: 12624954
The window A can assign a name to itself and pass it to children and they pass them to grandchildren.
0
 

Author Comment

by:troyd1
ID: 12626522
I guess that I am asking if you can reference the root window without giving it a name.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12626607
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
 
LVL 63

Expert Comment

by:Zvonko
ID: 12713299
Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question