473,406 Members | 2,451 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,406 software developers and data experts.

Parent to child back to parent

I have a question in the child and I need to pass the answer back to the
parent:

var go = 0
var mywin = null;
opts = 'width=300,height=300,status=yes,toolbar=no,menuba r=no,location=no'
mywin = window.open('','mywin',opts)
mywin.document.open()
mywin.document.write('<html><head><title>My Title</title>'
+'<script type="text/javascript">'
+'function sayyes() {'
+'go=1;'
+'window.close()'
+'}'
+'</script>'
+'</head><body>'
+'<p>Do you want to go or not?</p>'
+'<a href="#" onClick="sayyes()">Yes I do</a><br>'
+'<a href="#" onClick="window.close()">No I do not</a>'
+'</body></html>')
mywin.document.close()
if (go==1) {
do stuff
}

My problem is that the parent thinks var go is still 0 and doesn't get set
to 1. Any ideas?
Jul 23 '05 #1
2 1403
There are several ways of doing it. Try this by saving the code to an
..HTML file.

<script>
var go = 0
function shazam() {
alert(go);
}
function popWin () {
var mywin = null;
opts =
'width=300,height=300,status=yes,toolbar=no,menuba r=no,location=no'
mywin = window.open('','mywin',opts)
mywin.document.open()
mywin.document.write('<html><head><title>My Title</title>' +
'<script type="text/javascript">' +
'function sayyes(answer) {' +
'opener.go=answer;' +
'opener.shazam();' +
'window.close();' +
'}')
mywin.document.write('</'+'script>')
mywin.document.write('</head><body>' +
'<p>Do you want to go or not?</p>' +
'<a href="#" onClick="sayyes(1)">Yes I do</a><br>' +
'<a href="#" onClick="sayyes(0)">No I do not</a>' +
'</body></html>')
mywin.document.close()
}
</script>
<a href="javascript:popWin();">PopWin</a>

Jul 23 '05 #2
Adrian MacNair wrote:
I have a question in the child and I need to pass the answer back to the
parent:

var go = 0
var mywin = null;
opts = 'width=300,height=300,status=yes,toolbar=no,menuba r=no,location=no'
mywin = window.open('','mywin',opts)
mywin.document.open()
mywin.document.write('<html><head><title>My Title</title>'
+'<script type="text/javascript">'
+'function sayyes() {'
+'go=1;'
+'window.close()'
+'}'
+'</script>'
+'</head><body>'
+'<p>Do you want to go or not?</p>'
+'<a href="#" onClick="sayyes()">Yes I do</a><br>'
+'<a href="#" onClick="window.close()">No I do not</a>'
+'</body></html>')
mywin.document.close()
if (go==1) {
do stuff
}

My problem is that the parent thinks var go is still 0 and doesn't get set
to 1. Any ideas?

The parent is right-- you're not waiting for an answer. That, and your
popup isn't talking to the parent.

How about an answer() function that does your if( go ) logic?

In the parent:
function answer( go ) {
if( go ) {
// go do stuff
}
}
In the popup:
function answer( go ) {
// do some tests to find out if the parent is still
// relevant to this document, then...
window.opener.answer( go );
self.close();
return false;
}
<a href=# onclick=return(answer(true))>Sure, let's go</a>
<a href=# onclick=return(answer(no))>Nah... let's wait</a>

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Stuart McGraw | last post by:
I haven't been able to figure this out and would appreciate some help... I have two tables, both with autonumber primary keys, and linked in a conventional master-child relationship. I've...
2
by: Raj | last post by:
Hi All, I have a problem with trying to refresh the parent window from child window in order to update data in the parent window. The sequence of events are 1) I click a button in the parent...
1
by: Aaron Smith | last post by:
I have a parent table that has one child table. The parent has a single field (ID, AutoIncrement, Seed 0, Step -1 in the DataSet, Seed 1, step 1, in DataSource). The child is linked to this ID...
10
by: Goran Djuranovic | last post by:
Hi all, Does anyone know how to declare a variable in a class to be accessible ONLY from a classes instantiated within that class? For example: ************* CODE ***************** Public...
4
by: Richard Lewis Haggard | last post by:
What is the mechanism by which a child window can notify its parent that it has been clicked on? -- Richard Lewis Haggard www.Haggard-And-Associates.com
1
by: ace danger | last post by:
I have some javascript that works in Firefox 2 but not in IE 7. In the parent page, a user clicks a link and a new window is opened so that they can maintain some values. When the user is...
8
by: Rick | last post by:
VS 2005 I' m setting up a parent/child datagridviews in a form. I am doing a lot of this by hand coding in order to get the feel of things. I want a change in the parent table to trigger a...
1
by: Richard | last post by:
Greetings. I am total newbie to Javascript so what is written below is probably a bunch of cobblers!! Any assistance in correcting my code much appreciated. I wish the popped up child to pass...
1
by: varunvashishth | last post by:
hi, I'm facing a problem with displaying a child jsp on top of parent jsp. on clicking a link in parent jsp the child jsp opens up and it has some list of values and other textboxes which gets...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.