...

View Full Version : Method for referencing form data from a parent page



bherrington
03-18-2004, 08:21 AM
On a pop up page, how do I reference a form element from the parent page, whilst at the same time being able to reference the same form element if the "popped up" page was itself a pop up from another page? :confused:

Currently I have a form on "Page2" which opens a new window "Page3" populated by javascript based on the users selection from the form on Page2. I have previously always used the "opener" method to reference the form selection on Page2, i.e.;

javascriptvariable = opener.abcform.xyzelement.value

However I want to open Page3 either from Page2 directly or from [I]another page[I] (Page1) which opens Page2 as a pop up, from which the user selects as before to open Page3 as a pop up. However using the latter, the "opener" method in Page3 now doesn't work (I suspect because the "opener" method is looking for the form element in Page1 rather than Page2).

glenngv
03-18-2004, 08:36 AM
It's confusing. Maybe it's better to post some codes.

bherrington
03-18-2004, 08:57 AM
Originally posted by glenngv
It's confusing. Maybe it's better to post some codes.

:) Maybe I can pose a simpler question. I want to open a pop up window. On that pop up page, what other javascript methods than "opener"(eg "opener.abcform.xyzelement.value") can be used to reference a HTML form element on the original page?

glenngv
03-18-2004, 09:44 AM
That's the only way. And btw, "opener" is not a method, it's an object.

Regarding your actual problem, does the form and field names of page1 and page2 the same? If not, then you have to check if a particular field exists before accessing its value.

bherrington
03-18-2004, 10:15 AM
Regarding your actual problem, does the form and field names of page1 and page2 the same?

No, the form only exists on page2. Therefore if I open page 2 as a pop up from page1, I'd be stuffed as regards opening page3 as a pop up from page2? :(

glenngv
03-19-2004, 02:03 AM
I'm still confused. Can you explain with more details as possible. Perhaps post some related codes to make the whole picture clearer.

FastCougar
03-19-2004, 02:42 AM
Page 1:


<form name="frm1">
...
...
<input type='text' name='hello1' value=''>
<input type='button' ... onclick='popup1();'>
...
...
</form>

Page 2:


window.opener.document.frm1.hello1.value = 'Hello World';

<form name="frm2">
...
...
<input type='text' name='hello2' value=''>
<input type='button' ... onclick='popup2();'>
...
...
</form>

Page 3:


window.opener.document.frm2.hello2.value = 'Hello Again';

An opener is an opener is an opener. Page 1 is the "opener" to page 2 and page 2 is the "opener" for page 3 and so on.

glenngv
03-19-2004, 03:49 AM
But can you relate that to this question?


Originally posted by bherrington
However I want to open Page3 either from Page2 directly or from another page (Page1) which opens Page2 as a pop up, from which the user selects as before to open Page3 as a pop up. However using the latter, the "opener" method in Page3 now doesn't work (I suspect because the "opener" method is looking for the form element in Page1 rather than Page2).


and to this:

Originally posted by glenngv
Regarding your actual problem, does the form and field names of page1 and page2 the same?


Originally posted by bherrington
No, the form only exists on page2. Therefore if I open page 2 as a pop up from page1, I'd be stuffed as regards opening page3 as a pop up from page2?

bherrington
03-19-2004, 07:46 AM
:) Actually, I stumbled across an easier solution, the reasons for which are not entirely clear to me. Provided I use a different function for opening a new window from Page1 -> Page2 as I do to open a new window from Page2 -> Page 3, this works fine, JS code in Page3 can reference a HTML form element in Page2 using "opener.". In addition, opening Page2 directly and running Page3 as a new window from it also works perfectly well. I'm not sure why the JS I was using for new windows would conflict, but it might have been the naming of Page2 as a pop up, which would still be open at the point that the call was made to open Page3 as a similar pop-up (that said, the page itself opened fine, it was just that the JS wouldn't pick up the reference to the HTML form element to create the data I wanted :confused: ).

:D Fortunately I am comfortable living my life finding success accidentally without understanding every aspect of javascript at a fundamental level!! :D

Thanks anyway. :thumbsup: :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum