Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript window.opener

Status
Not open for further replies.

fisa

Programmer
Nov 28, 2003
19
GB
Hi all,

I am a novice with javascripts. The problem I am facing is as follows:

I am trying to get the the value of one of the input fields of a window from it's child window. I am making use of "window.opener" for the same as follows:

val = window.opener.test1.sysname.value
alert(val)

where test1 is the name of the Frame in the parent window , which has the input field sysname in it.

This doesn't work. The script stops execution at this point and no alert box is thrown. No error messages also.

what I am curious here is, window.opener just works fine with the other forms in the parent document and returns the field values in the other forms. Only with one the forms(ie, test1) it dosn't work. What could be the probable reason?

please shed some light into this....This is a bit urgent. Please revert back to me for any additional input from my end.

Thanks in advance.
 
Enable show notification on every script error in IE to see errors; then use alert to alert (window.opener.test1.sysname) to see if it will show up as [object].

In fact, i'd rather use window.opener.document.getElementById (or ...sByName) to get the input

 
try:
window.opener.document.sysname.value


Known is handfull, Unknown is worldfull
 
Friend,

Thanks a lot for ur replies. I have tried out the suggestions but still it does not work.

To clarify the scenario further, please note that the input field element that I am trying to access is present in the same form from where I call a java script function that opens up the child window. I am trying to access the field value from this child window only. Does this make any difference , as I am able to access the field values from other forms (say , test2)using
window.opener.test2.owner.value

Please let me know ur comments. I am waiting...Thanks in advance.
 
[tt]>val = window.opener.test1.sysname.value[/tt]
>where test1 is the name of the Frame in the parent window , which has the input field sysname in it.

Try this.
[tt]val=window.opener.parent.frames["test1"].document.forms["formname"].elements["sysname"].value[/tt]

I used the elaborated form to reference the element in order to make thing crystal clear. (If sysname is the element's name, you seem to have not provide us the "formname" above.)
 
Hi,

I have tried the following:

val = window.opener.parent.document.forms["test1"].elements["sysname"].value

and it did not work. Please note thatI don't have any frames defined in the parent html page.

Also, I am able to access the field value when I defined the field in a dummy form, outside the form that actually calls the javascript function which opens the child window. Is this a clue? Do I need to change the syntax or something , just because I am trying to access a field value that is present within the same form that calls for a javascript function, which actually opens the child window?

Please shed some light...Thanks.
 
post #1
>where test1 is the name of the Frame in the parent window
and now
> Please note thatI don't have any frames defined in the parent html page.
I don't get it.
 
Hi,

Thanks for pointing out a typo in my first communication. Please read the same as "where test1 is the name of the form in the parent window , which has the input field sysname in it."

Thanks again...There is no frame defined in the parent html page. It has only forms in it.
 
Always quote from post #1
>I am trying to get the the value of one of the input fields of a window from it's child window

So are you saying val=... line in the window where window.open (...) is written? I don't really know what to believe or what not. Every thing seems to suggest you want to access "window.opener" from the popup (new window)!

If the new understanding is correct, then it is this.

With you window.open line, assign the return object to a variable. That is instead of this:
[tt] window.open ("xyz")[/tt] //or including other params
do this
[tt] var owin=window.open("xyz")[/tt]
Then you access the val like this.
[tt] val=owin.test1.sysname.value[/tt]
(But, are test1, sysname in the popup? Who knows, maybe not...)
 
Hi,

My apologies if there was a confusion. Let me clarify the scenario.

Window1(parent)
--------
has many forms defined within. One of them is test1. test1 has many input fields. One of them is sysname.

There is a link defined within test1 , which onClick calls for a javascript function(say, f1). This functtion opens a new window , using window.open(). Let's call this new window as Window2.

Window2(child)
-----------

has a button which onclick calls for a javascript function (say, f2)present in window2, itself. f2 is the java script function that tries to get the value of sysname from Window1. What I do in f2 is

val = window.opener.parent.document.forms["test1"].elements["sysname"].value
alert(val)

But, I am not getting any alert box thrown or error messges. There is no response to the button click in Window2.

Hope the scenario is clear now. If not, please do revert back.

I am quite new to javascripts. Thanks again for ur patience..

 
Try this.
[tt]
val = window.opener.forms["test1"].elements["sysname"].value
[/tt]
This should also be equivalent to and equally correct.
[tt]
val = window.opener.test1.sysname.value
[/tt]
If both fails, you make a new discovery or it is some other code before them which is incorrect, a typo, a unclose parentheses/quotes... Use firefox's javascript console to locate them.
 
Hi,

I tried both the suggestions and both did not work.

There is no other problem with the code. If I comment out just this statement everything goes through fine.

Please let me know, if the approach to the scenario(explained above) is fine. I am totally clueless to what is happening...
 
Also, please note that I am able to access the field variables present in other forms of parent window , using the same code. Only for this form(test1), it fails.

Does it give any clue?
 
Well, post your complete code for both windows. Even a thousand lines, it would worth it.
 
Hi,

Posting the complete code requires permissions to be granted by the autorities.

Anyway I will try for the same.

Thanks for ur help.
 
No problem. Your form test1 contains error, that would be it. You just have to look closer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top