Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Parent to child back to parent

Reply
Thread Tools

Parent to child back to parent

 
 
Adrian MacNair
Guest
Posts: n/a
 
      05-26-2005
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?


 
Reply With Quote
 
 
 
 
SEvans
Guest
Posts: n/a
 
      05-26-2005
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="javascriptopWin();">PopWin</a>

 
Reply With Quote
 
 
 
 
Random
Guest
Posts: n/a
 
      05-26-2005
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>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If a class Child inherits from Parent, how to implementChild.some_method if Parent.some_method() returns Parent instance ? metal Python 8 10-30-2009 10:31 AM
Parent - Child back to parent javascript thingybob mark ASP .Net 1 03-10-2005 02:20 PM
Pass from parent to child, then update parent with child value... Noel Dolan Javascript 0 07-18-2004 05:52 PM
EJB: How to delete child entries from a parent-child CMR one-to-many relationship? davout Java 0 04-18-2004 07:02 PM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM



Advertisments