PDA

View Full Version : Sending value from popup back to parent?


angst
01-04-2006, 05:14 PM
hello!

I'm wondering how I can have a popup window with links, send a value back to the parent window by click on the link in the popup?

can anyone point me in the right direction?

thanks in advance for your time!

-ken

angst
01-04-2006, 05:44 PM
kind of like this:

parent:

<script>

child = null;

function show_age_calculator ()
{
child = open
(
"age_calculator.html",
"age_calculator",
"width=400,height=200"
);
}

function keep_child_on_top ()
{
if (child != null)
if (child . closed)
child = null;
else
child . focus ();
}

</script>

<body onFocus="keep_child_on_top ();">

<form name=f onSubmit="self . close (); return false;">

<input type=text name=age size=10 maxlength=10><br />
<a href="javascript:show_age_calculator ();">click here</a>
</form>

<script>
document . f . age . focus ();
</script>




Child

<script>

function exit ()
{
var age = tya.value;
if (isNaN (age))
{
//alert ("Please enter an integer.");
tya . value = "";
tya . focus ();
return;
}

if (! opener . closed)
opener . document . f . age . value = age;
close ();
}

</script>

<body onLoad="tya . focus ();">

<form name=f onSubmit="exit (); return false;">
<p>
<input type=text name=tya size=10>
<p>
<input type=submit value="OK">
<input type=button value="cancel" onClick="self . close ();">
</form>
</center>
<script>

tya = document . f . tya;

</script>



but, I need it to be able to use a link, insted of a form for the child window,
also this only seems to handle numbers, and I need it to be able to handle text, and I don't know enough javascript yet to do this myself without any explanation.

any help would be great!

thanks again for your time,
-Ken

angst
01-04-2006, 06:05 PM
ok,
well I've gotten a little further.

child:

<script>
function exit ()
{
var prod = tya.value;

if (! opener.closed)
opener.document.myform.prod.value=prod;
close ();
}
</script>

<body onLoad="tya . focus ();">

<form name=myform onSubmit="exit (); return false;">

<span onclick="document.form.submit(tya='test')">test</span><br /><br />

<input type=text name=tya size=10>
<input type=submit value="OK">
<input type=button value="cancel" onClick="self . close ();">
</form>


<script>
tya = document . myform . tya;
</script>


I can now enter text now and it submits it to the parent window,
but I'd still rather use a link, or something like:

<span onclick="document.form.submit(tya='test')">test</span>

but thats not working for me,
any ideas?

thanks again,
-ken

angst
01-04-2006, 08:52 PM
ok,
one more try,

my code now:

<script>
function go () {
//var prod = tya.value;

var prod = document.getElementById('tya').innerHTML;
if (! opener . closed)
opener . document.f.prod.value = prod;
self.close();

}
</script>
<div id="tya" value="test" onClick="go();">test</div>
<div id="tya" value="blah" onClick="go();">blah</div>


<script>
tya = document.f.tya;
</script>
<br /><br />
<input type=button value="cancel" onClick="self . close ();">



now I can just click on the <div> and it moves the data into the parent window, my only problem now is that I can only use one at a time,
even if I click on the second div "blah", it just inserts "test" still,

can anyone please help me with this?

thanks again for your time!

-Ken

fishluvr
01-04-2006, 09:21 PM
1) All IDs should be unique...

<div id="tya1" onClick="go(this.id);">test</div>
<div id="tya2" onClick="go(this.id);">blah</div>

2) Using the above divs, change your function to:

function go (which) {
var prod = document.getElementById(which).innerHTML;
if (!opener.closed) {
opener.document.f.prod.value = prod;
}
self.close();
}

EDIT: Removed the values from the divs...Didn't notice those...

angst
01-04-2006, 10:00 PM
kool!
seems to simple now that i see it;-)

thanks!
-Ken