troyd1
asked on
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.FIEL D.value='n ewvalue'.
How can I do first.opener.document.form 1.FIELD.va lue='newva lue'
Thanks
I have done opener.document.form1.FIEL
How can I do first.opener.document.form
Thanks
like you have your main page, that opens a window, that page opens a window
it would be
window.opener.opener.docum ent.form1. FIELD.valu e - 'newvalue'
it would be
window.opener.opener.docum
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.htm l", '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();">Valu e 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.v alue
var ls_text = document.frm_child.t1.valu e;
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
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.htm
}
function getValue() {
document.write("Value is : " + ls_value);
}
//-->
</script>
</head>
<body onload="call();">
<a href="#" onClick="getValue();">Valu
</body>
</html>
<###### HTML code for childwnd.html ######>
<html>
<head>
<script language="javascript">
<!--
function call_return() {
//var ls_text = document.frm_child.text1.v
var ls_text = document.frm_child.t1.valu
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
ASKER
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
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
I think zvonko's solution is the best, but not exactly what I was asking.
Thanks, Troy
The window A can assign a name to itself and pass it to children and they pass them to grandchildren.
ASKER
I guess that I am asking if you can reference the root window without giving it a name.
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>
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>
Thanks.
cheers
sean