473,386 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How can a screen identify its parent in all cases?

35
Here is my scenario:

Screen A ===> Screen B ===> Screen C
\\
\\
V
Screen C

What this means is that sometimes Screen A opens B that opens C; other times Screen A opens C directly and B is not used.

The question is: How does C always know who opened it -- A or B? This is essential to know for later processing.

I have tried passing an ID value from A to C and from B to C so C can know its parent, but I always run into the problem of the browser interpreter stating that the code-of-the-path-that-is-not-the-parent-this-time "has no properties" and that error causes processing to stop. So far the "try/finally" statement has not worked for me in bypassing this error.

What I really need is the ability to catch an error the interpreter identifies and let me safely defuse it so that processing continues.

If there is no such ability in Javascript, I need some fresh ideas how to do what I want without generating these processing errors.

Thanks to all who can help.
Dec 5 '07 #1
12 1763
acoder
16,027 Expert Mod 8TB
Why can't you just use window.opener? That should identify the parent window.
Dec 5 '07 #2
trbjr
35
Why can't you just use window.opener? That should identify the parent window.
I do use "window.opener.document.formname.field.value" for the path I am using and it works fine.

But the same code for the path that is not active for the opposite scenario is the path that the browser issues the message of "has no properties".

Screen C has code in it for both paths (opened by A; also, opened by B). It is the code for the non-active path that causes the browser to complain.
Dec 5 '07 #3
acoder
16,027 Expert Mod 8TB
Screen C has code in it for both paths (opened by A; also, opened by B). It is the code for the non-active path that causes the browser to complain.
Ah, I see what you mean.

You could pass a parameter with the URL. If it's a server-side page, use GET parameter handling and if it's HTML, use location.search to parse the query string, e.g. "?pageB=1".
Dec 5 '07 #4
trbjr
35
Ah, I see what you mean.

You could pass a parameter with the URL. If it's a server-side page, use GET parameter handling and if it's HTML, use location.search to parse the query string, e.g. "?pageB=1".
That sounds interesting. I will try to remember that when I am working on a server side project. But this is all client side.

I have another idea that I am working on.

If I created a DOM object inside the body but outside the form, then the code "window.opener.document.fieldname.value", I am hoping, would work. As I see it now, there would be no unique form name that would confuse the browser. If Screen A and Screen B had the same field name, then Screen C should access that field based only on the browser knowing who the parent was (Screen A or B).

If that works, then the value in the field would tell Screen C who the parent was, because Screen A and B would place differing values in the field.

This idea hinges on being able to set up a same named field in both screens outside the form. If "window.opener" works only if a field is inside a form, then I am back to the beginning again.

I am trying to research this now using Javascript the Definitive Guide by David Flanagan.

Let me know your reaction to this tack.
Dec 6 '07 #5
acoder
16,027 Expert Mod 8TB
If I created a DOM object inside the body but outside the form, then the code "window.opener.document.fieldname.value", I am hoping, would work. As I see it now, there would be no unique form name that would confuse the browser. If Screen A and Screen B had the same field name, then Screen C should access that field based only on the browser knowing who the parent was (Screen A or B).

If that works, then the value in the field would tell Screen C who the parent was, because Screen A and B would place differing values in the field.

This idea hinges on being able to set up a same named field in both screens outside the form. If "window.opener" works only if a field is inside a form, then I am back to the beginning again.
Fields should be inside forms. You can either have another form and put the field inside that form, or even better, just include it within the current form, but access by its id rather than the form notation, i.e. using document.getElementById. Then, there's no need to worry about form names.
Dec 7 '07 #6
trbjr
35
Fields should be inside forms. You can either have another form and put the field inside that form, or even better, just include it within the current form, but access by its id rather than the form notation, i.e. using document.getElementById. Then, there's no need to worry about form names.
I like the getElementById suggestion. But even using that it seems to me (without having tried it) that I would still have the same problem I have now. Screen C still has to know its parent on each usage cycle. That means I put code in C to handle both Screen A and B as parents.

Whichever parent is the real path, won't the code for the non-active, opposite path still get the "has no properties" error?

===============================================

Here's an idea that research turned up. What do you think of it?

Flanagan in Javascript the Definitive Guide (item 15.3.1) says that if two document elements have name attributes with the same value, the document property becomes an array that holds references to both elements.

Supposing I named Screens A and B with the same name. That should get rid of the interpreter's "no properties" error message. I would then have to analyze the values inside the array to determine whether A or B was the parent of C.

It sounds pretty slick, but I wonder if Flanagan is talking about naming two different screens with the same name or two elements within one screen. I suspect the latter.
Dec 7 '07 #7
acoder
16,027 Expert Mod 8TB
Can you post the part of the code which is causing the problem, so I can see what check you're making.
Dec 10 '07 #8
trbjr
35
Can you post the part of the code which is causing the problem, so I can see what check you're making.
When I went to show you the code for Screen 3, I found that it had changed from the time of the initial posting. Right now I cannot show the original code that caused me to make the initial posting.

What I have now is code that works for the path that goes from screen 1 to 2 to 3. When I am on the alternate path (screen 1 to 3), the code that references the first path is still in the program and the explicit reference to screen 2 generates the error, because screen 2 is not in the path used and so is not identified as the parent.

In the comments: adp2 = screen 1, adpvisa = screen 2, adp3 = screen 3
In the code below the word "visaform" is the form name of screen 2.

Expand|Select|Wrap|Line Numbers
  1.  
  2. function whoIsParent() {  // determine if apd3 is opened by adp2 or by adpvisa
  3.         try {
  4.         f3choice = window.opener.document.visaform.visaopen.value;
  5.         }
  6.         finally {    
  7.             if  (f3choice == 'V') {               //  'V' = visa authorization
  8.                 threeopenedbyvisa = "Y";    //  adp user in US via visa
  9.                 threeopenedbytwo = "N";
  10.             }
  11.             else {
  12.                 threeopenedbytwo = "Y";     // this means adp user not in US via visa
  13.                 threeopenedbyvisa = "N";
  14.             }
  15.         }
  16.     }
  17.  
Over the week-end I thought more about the getElementById option and am working on that now. I hope to be able to report results later today.
Dec 10 '07 #9
trbjr
35
When I went to show you the code for Screen 3, I found that it had changed from the time of the initial posting. Right now I cannot show the original code that caused me to make the initial posting.

What I have now is code that works for the path that goes from screen 1 to 2 to 3. When I am on the alternate path (screen 1 to 3), the code that references the first path is still in the program and the explicit reference to screen 2 generates the error, because screen 2 is not in the path used and so is not identified as the parent.

In the comments: adp2 = screen 1, adpvisa = screen 2, adp3 = screen 3
In the code below the word "visaform" is the form name of screen 2.

Expand|Select|Wrap|Line Numbers
  1.  
  2. function whoIsParent() {  // determine if apd3 is opened by adp2 or by adpvisa
  3.         try {
  4.         f3choice = window.opener.document.visaform.visaopen.value;
  5.         }
  6.         finally {    
  7.             if  (f3choice == 'V') {               //  'V' = visa authorization
  8.                 threeopenedbyvisa = "Y";    //  adp user in US via visa
  9.                 threeopenedbytwo = "N";
  10.             }
  11.             else {
  12.                 threeopenedbytwo = "Y";     // this means adp user not in US via visa
  13.                 threeopenedbyvisa = "N";
  14.             }
  15.         }
  16.     }
  17.  
Over the week-end I thought more about the getElementById option and am working on that now. I hope to be able to report results later today.
==================================================

Over the week-end I thought more about the getElementById option and am working on that now. I hope to be able to report results later today.
Referring to the code above the "====" line, here is how I changed the "try" statement in screen 3:

Expand|Select|Wrap|Line Numbers
  1.  
  2.         try {
  3.         f3parcode = window.opener.document.getElementById("parcode").value;   
  4.                // parcode carries value indicating parent
  5.                // parcode is set in both screen 1 and screen 2
  6.               }
  7.  
The above gives me the error message:

"window.opener.document.getElementById("parcod e") has no properties"

Since the error message does not mention the ".value" part of the above code, is it incorrect to use ".value" with getElementById?

Or is the error that you cannot use getElementById with window.opener to get at a field in the parent?

Or is there something not apparent to me?

TIA
Dec 10 '07 #10
acoder
16,027 Expert Mod 8TB
Since the error message does not mention the ".value" part of the above code, is it incorrect to use ".value" with getElementById?
It depends on whether the element has a value attribute or not. If it doesn't, you may need to use innerHTML. How do you define the element on the two pages?
Dec 11 '07 #11
trbjr
35
It depends on whether the element has a value attribute or not. If it doesn't, you may need to use innerHTML. How do you define the element on the two pages?
Today everything is working as desired. No error messages.

The only think I can think to explain this is that the browser was accessing older, saved versions of the screens rather than the updated ones. After each update I saved everything and refreshed the screens, I thought. Since things seemed not to work, I kept trying for new ideas.

Screen 1:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <input type="hidden" id="parcode" name="adp2open" value="2" axlength="1">
  3.  
  4.  
Screen 2:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <input type="hidden" id="parcode" name="visaopen" value="V" maxlength="1">
  3.  
  4.  
Thanks very much for all your time and support. I really appreciate it. Your idea of getElementById() was the key to successful processing combined with the idea of using the same name for parent code in the two screens.
Dec 11 '07 #12
acoder
16,027 Expert Mod 8TB
You're welcome. Glad you got it working.

PS. To close the code tags properly, remove the space in [ /CODE].
Dec 12 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Skully Matjas | last post by:
I am using the following code (created by the wizard) to allow to bring my form to a particular entery. But when I edit the entery (ex: put new information into a blank cell), it puts that record...
6
by: Woody Splawn | last post by:
I know that I can do the following to identify the parent name of an active control Dim sParentName As String = ActiveControl.Parent.Name But how do I identify the name of the active control?...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
3
by: steve | last post by:
Hi All I have textboxes within a TableLayoutpanel and I want to be able to position an independant control adjacent to a selected textbox This independent control allows selection of text to...
6
by: Pieter | last post by:
Hi, For some procedures that throws exceptions, I would like to show different messages to the user depending on what type of exception he's getting. For instance this one: when the file is...
3
by: ApexData | last post by:
I am using the Shortcut Menu Bar property of many combobox controls to execute a single shared custom function. When the function executes, I need it to immediately identify the following items:...
16
by: Alan Jones | last post by:
Hello everyone, any help would be greatly appreciated. :) What I'm trying to do may not be advisable, but here goes... I want a page named signature.php to appear conditionally as an include...
6
by: xla76 | last post by:
I have a simple treeview (treeview1) to which I have added two nodes (nodeA and nodeB) which have n levels of child nodes. What I want is to be able to identify whether the child node I select...
0
Shashi Sadasivan
by: Shashi Sadasivan | last post by:
Hi All, i Have an application functionaluty which has 4 forms which are needed to interact by the user by dragging data from these forms to one another the main form is located in the MDI Parent...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.