How do you pass info from a pop-up window back to the parent?

  • Thread starter Thread starter Jack Brewster
  • Start date Start date
J

Jack Brewster

Basically, I want to pass form results from the pop up back to a form in the
parent window.

Does anyone have or know of an example or tutorial that would help me with
this?

Thanks
 
I recently overcame the hassle of sending form info (and hidden fields)
through to a pop-up form that was popped with JavaScript.
If you could explain a little more detail, maybe your situation and mine
aren't so different.
 
Pretty standard stuff, really. All IE6.

The popup will step the user through a couple select lists, each paring down
the next until I reach the last select (think Wizard). That's select's
value will be passed back to the parent window and populate a field.

Since I posted, I've been mucking about with using:
self.opener.document.formname.fieldname.value = 'foo';

But each time I receive an error:
'self.opener.document.formname.fieldname' is null or not an object

I've found if I don't use named elements and instead code like so:
self.opener.document.forms['formname'].elements['fieldname'].value = 'foo';

or even:
self.opener.document.forms['formname'].fieldname.value = 'foo';

the script works. I've looked at several examples that have all named
references so I'm not sure why it's failing. I can use the 'long form' if I
have to, but I'd rather use straight formname.fieldname refrencing if
possible.

I may have the popup pass hidden values as well, I'm still working out what
I want stored in the db. My guess is that I'd just need to add a ...value =
'whatever' statement for each form field. But if you have additional
guidance, do tell. :)

Thanks for your interest.

--
Jack Brewster - Microsoft FrontPage MVP


chris leeds said:
I recently overcame the hassle of sending form info (and hidden fields)
through to a pop-up form that was popped with JavaScript.
If you could explain a little more detail, maybe your situation and mine
aren't so different.
 
already you've learned more than I did in my problem. ;-)
I have a little script for menus that makes the pop-ups nav links open in
the parent window.
but I was thinking, why not just put the form into a "layer". that way it's
all on the same page and you'd just be submitting the form to itself. it'd
just look like a pop-up.
I had a problem passing the opening page name through to a form on a pop-up
window, so I guess yours is the reverse of that. I thought of the layer
approach only after I worked out the pop-up issue, so I didn't try.
HTH

--
The email address on this posting is a "black hole". I got tired of all the
spam.
Please feel free to contact me here:
http://nedp.net/contact/
--


Jack Brewster said:
Pretty standard stuff, really. All IE6.

The popup will step the user through a couple select lists, each paring down
the next until I reach the last select (think Wizard). That's select's
value will be passed back to the parent window and populate a field.

Since I posted, I've been mucking about with using:
self.opener.document.formname.fieldname.value = 'foo';

But each time I receive an error:
'self.opener.document.formname.fieldname' is null or not an object

I've found if I don't use named elements and instead code like so:
self.opener.document.forms['formname'].elements['fieldname'].value = 'foo';

or even:
self.opener.document.forms['formname'].fieldname.value = 'foo';

the script works. I've looked at several examples that have all named
references so I'm not sure why it's failing. I can use the 'long form' if I
have to, but I'd rather use straight formname.fieldname refrencing if
possible.

I may have the popup pass hidden values as well, I'm still working out what
I want stored in the db. My guess is that I'd just need to add a ...value =
'whatever' statement for each form field. But if you have additional
guidance, do tell. :)

Thanks for your interest.
 
Basically, I want to pass form results from the pop up back to a form in the
parent window.

This is a really bad idea. Are you sure you want to head in this
direction ?
 
Bob said:
This is a really bad idea. Are you sure you want to head in this
direction ?

Care to elaborate? It's for an intranet app so I'm able to target the
browser, if that's your concern.

I'd be happy to be talked out of it, but it's the best course of action
based on the information I have on hand.
 
Steve,

I'm getting DNS errors with that URL both here at work and on a remote site.
Can you verify it?

--
Jack Brewster - Microsoft FrontPage MVP

Steve Easton said:
Jack, is this anything similar to what you're trying to do?
http://www.webteacher.com/javascript/changing_lists/


--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
.......................with a computer
 
I already know how to work with new windows and now you want me to play with
layers??! :) I might give it a go, but I'm not sure how this would be
implemented. Perhaps you can provide a little direction?

--
Jack Brewster - Microsoft FrontPage MVP

chris leeds said:
already you've learned more than I did in my problem. ;-)
I have a little script for menus that makes the pop-ups nav links open in
the parent window.
but I was thinking, why not just put the form into a "layer". that way it's
all on the same page and you'd just be submitting the form to itself. it'd
just look like a pop-up.
I had a problem passing the opening page name through to a form on a pop-up
window, so I guess yours is the reverse of that. I thought of the layer
approach only after I worked out the pop-up issue, so I didn't try.
HTH

--
The email address on this posting is a "black hole". I got tired of all the
spam.
Please feel free to contact me here:
http://nedp.net/contact/
--


Jack Brewster said:
Pretty standard stuff, really. All IE6.

The popup will step the user through a couple select lists, each paring down
the next until I reach the last select (think Wizard). That's select's
value will be passed back to the parent window and populate a field.

Since I posted, I've been mucking about with using:
self.opener.document.formname.fieldname.value = 'foo';

But each time I receive an error:
'self.opener.document.formname.fieldname' is null or not an object

I've found if I don't use named elements and instead code like so:
self.opener.document.forms['formname'].elements['fieldname'].value = 'foo';

or even:
self.opener.document.forms['formname'].fieldname.value = 'foo';

the script works. I've looked at several examples that have all named
references so I'm not sure why it's failing. I can use the 'long form'
if
I
have to, but I'd rather use straight formname.fieldname refrencing if
possible.

I may have the popup pass hidden values as well, I'm still working out what
I want stored in the db. My guess is that I'd just need to add a
....value
=
'whatever' statement for each form field. But if you have additional
guidance, do tell. :)

Thanks for your interest.

--
Jack Brewster - Microsoft FrontPage MVP


all
the
form
in me
with
 
Jack,
Just checked it and it opened right up.

It's an example of two drop down select boxes, Selecting an option in the first
populates the second.
Probably not what you want.

--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed..................
...............................with a computer

Jack Brewster said:
Steve,

I'm getting DNS errors with that URL both here at work and on a remote site.
Can you verify it?
 
I think it would have to be done using an external js file with a global
variable set and also containing the functions.

1 function called from the pop up which reads the value and passes it to the
global variable and then also calls
function 2 which writes the global variable to the form field using:

<script>
var readit;
function read()
readit = (document.all.formname.src = fieldname.value);

new function write (){
document.all.formname.fieldname.innerHTML = "readit";
}}
</script>

Then the pop up would contain: onclick="readit"

Also you would have to call the script in both pages.

Not exact but maybe it gives you an idea.

--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed..................
...............................with a computer
 
Actually, the solution I've found is pretty straightforward.

In the parent page:
<form name="formname">
<input name="fieldname" />
</form>

In the pop up page:
<a href="#" onclick="changeFieldValue();">Test</a>

In the .js file:
function changeFieldValue() {
// Change the field value in the parent page
self.opener.document.formname.fieldname.value = 'foo';

// Close the pop up window
self.close();
}

The example above uses a link on the popup page to call
"changeFieldValue()", but it could be just as easily assigned to a form
action (onchange, onsubmit, etc.) to pass a form field's value.

The only hiccup at this point is that I'm coding XHTML 1.1 and name="" isn't
valid, only id="". I need to straighten out my DOM references to make it
compliant, but that's a small hurdle now.

Thanks to everyone for their assistance.

--
Jack Brewster - Microsoft FrontPage MVP

Steve Easton said:
I think it would have to be done using an external js file with a global
variable set and also containing the functions.

1 function called from the pop up which reads the value and passes it to the
global variable and then also calls
function 2 which writes the global variable to the form field using:

<script>
var readit;
function read()
readit = (document.all.formname.src = fieldname.value);

new function write (){
document.all.formname.fieldname.innerHTML = "readit";
}}
</script>

Then the pop up would contain: onclick="readit"

Also you would have to call the script in both pages.

Not exact but maybe it gives you an idea.

--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed..................
..............................with a computer
 
perhaps someone who's already been using the "layers and behaviors" like Mr.
Spivey, unless the JavaScript that shows the layer obfuscates the connection
between the page and the form.
I'm real interested in this so I'd like to encourage you! ;-)

--
The email address on this posting is a "black hole". I got tired of all the
spam.
Please feel free to contact me here:
http://nedp.net/contact/
--


Jack Brewster said:
I already know how to work with new windows and now you want me to play with
layers??! :) I might give it a go, but I'm not sure how this would be
implemented. Perhaps you can provide a little direction?

--
Jack Brewster - Microsoft FrontPage MVP

chris leeds said:
already you've learned more than I did in my problem. ;-)
I have a little script for menus that makes the pop-ups nav links open in
the parent window.
but I was thinking, why not just put the form into a "layer". that way it's
all on the same page and you'd just be submitting the form to itself. it'd
just look like a pop-up.
I had a problem passing the opening page name through to a form on a pop-up
window, so I guess yours is the reverse of that. I thought of the layer
approach only after I worked out the pop-up issue, so I didn't try.
HTH

--
The email address on this posting is a "black hole". I got tired of all the
spam.
Please feel free to contact me here:
http://nedp.net/contact/
--


Jack Brewster said:
Pretty standard stuff, really. All IE6.

The popup will step the user through a couple select lists, each
paring
down
the next until I reach the last select (think Wizard). That's select's
value will be passed back to the parent window and populate a field.

Since I posted, I've been mucking about with using:
self.opener.document.formname.fieldname.value = 'foo';

But each time I receive an error:
'self.opener.document.formname.fieldname' is null or not an object

I've found if I don't use named elements and instead code like so:
self.opener.document.forms['formname'].elements['fieldname'].value = 'foo';

or even:
self.opener.document.forms['formname'].fieldname.value = 'foo';

the script works. I've looked at several examples that have all named
references so I'm not sure why it's failing. I can use the 'long
form'
if ...value form
 
damn it. I was hoping you'd resort to a layer! ;-)

--
The email address on this posting is a "black hole". I got tired of all the
spam.
Please feel free to contact me here:
http://nedp.net/contact/
--


Jack Brewster said:
Actually, the solution I've found is pretty straightforward.

In the parent page:
<form name="formname">
<input name="fieldname" />
</form>

In the pop up page:
<a href="#" onclick="changeFieldValue();">Test</a>

In the .js file:
function changeFieldValue() {
// Change the field value in the parent page
self.opener.document.formname.fieldname.value = 'foo';

// Close the pop up window
self.close();
}

The example above uses a link on the popup page to call
"changeFieldValue()", but it could be just as easily assigned to a form
action (onchange, onsubmit, etc.) to pass a form field's value.

The only hiccup at this point is that I'm coding XHTML 1.1 and name="" isn't
valid, only id="". I need to straighten out my DOM references to make it
compliant, but that's a small hurdle now.

Thanks to everyone for their assistance.

--
Jack Brewster - Microsoft FrontPage MVP

Steve Easton said:
I think it would have to be done using an external js file with a global
variable set and also containing the functions.

1 function called from the pop up which reads the value and passes it to the
global variable and then also calls
function 2 which writes the global variable to the form field using:

<script>
var readit;
function read()
readit = (document.all.formname.src = fieldname.value);

new function write (){
document.all.formname.fieldname.innerHTML = "readit";
}}
</script>

Then the pop up would contain: onclick="readit"

Also you would have to call the script in both pages.

Not exact but maybe it gives you an idea.

--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed..................
..............................with a computer
in
 
If I get some steering in that direction, I'd be happy to. But since the
method I have works, I'm not going spend time reinventing the wheel. :)
 
If I get some steering in that direction, I'd be happy to. But since the
method I have works, I'm not going spend time reinventing the wheel. :)

Sorry, dropped off the planet. The reason that it's a really bad idea
is that the user may close the parent window and leave the child open.
They may also minimize the parent, causing additional confusion,
although you can do some convoluted coding to pop the parent back up
if it exists. But you can't do anything to recreate it if it's exited
and your child window is now an orphan.

Why would you need to have the contents of a child window update the
parent ? Some sort of interim calculation ?
 
The problem is I have to provide a series of selects, each choice paring
down the next one. If I populated the last select with all the records,
there would be over 2000 options...not user friendly.

Due to the nature of the data entry, having the page reload each time the
user picks from a select isn't efficient. So, I've chosen to move the
action to a popup and pass just the final selection to the main window.

Normally I do avoid JavaScript tricks like this, but it's for an intranet
app and I get to train the users. :)

If you can suggest a better method, I'd be happy to consider it.
 
Frames or IFrames are one option
See
http://tech.irt.org/articles/js042/index.htm

--




| The problem is I have to provide a series of selects, each choice paring
| down the next one. If I populated the last select with all the records,
| there would be over 2000 options...not user friendly.
|
| Due to the nature of the data entry, having the page reload each time the
| user picks from a select isn't efficient. So, I've chosen to move the
| action to a popup and pass just the final selection to the main window.
|
| Normally I do avoid JavaScript tricks like this, but it's for an intranet
| app and I get to train the users. :)
|
| If you can suggest a better method, I'd be happy to consider it.
|
| --
| Jack Brewster - Microsoft FrontPage MVP
|
| | > On Wed, 24 Mar 2004 16:23:26 -0800, "Jack Brewster"
| >
| > >If I get some steering in that direction, I'd be happy to. But since the
| > >method I have works, I'm not going spend time reinventing the wheel. :)
| >
| > Sorry, dropped off the planet. The reason that it's a really bad idea
| > is that the user may close the parent window and leave the child open.
| > They may also minimize the parent, causing additional confusion,
| > although you can do some convoluted coding to pop the parent back up
| > if it exists. But you can't do anything to recreate it if it's exited
| > and your child window is now an orphan.
| >
| > Why would you need to have the contents of a child window update the
| > parent ? Some sort of interim calculation ?
| >
| >
|
|
 
Frames or IFrames are one option

That'd be my direction too. With frames, if the parent disappears,
the child goes too. The coding is easy between the windows, etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top