Debt Consolidation - Submit article - Self Improvement Articles Directory - Deaf Topics - Find jobs

PDA

View Full Version : Passing variables from pop-up window to parent window.


FRYO
Oct 25th 2005, 12:48 pm
Hello,

I made a code to pass variables from pop-up window to parent window. Unfortunately this code is only working on Mozilla FireFox and not Internet Explorer. Can anyone help in this?

JavaScript function to pass variables and close pop-up window:
function setValues()
{
var txt = document.getElementById("text").value;
var font_size = document.getElementById("font_size").value;
var font = document.getElementById("font");
font = font.options[font.selectedIndex].value;
var text_location = document.getElementById("text_location");
text_location = text_location.options[text_location.selectedIndex].value;
var color = document.getElementById("color").value;

if (txt.length < 1 || font.length < 1 || font_size.length < 1 || font_size.toInt() < 1 ||
font.length < 1 || text_location.length < 1 || color.length != 7 || color[0] != '#')
{
alert("Please fill out all the fields correctly!");
return false;
}

var ncolor = parseInt(color.substr(1,2), 16) + "," + parseInt(color.substr(3,2), 16) + "," + parseInt(color.substr(5,2), 16);


opener.document.getElementById("text").value = txt;
opener.document.getElementById("font").value = font;
opener.document.getElementById("font_size").value = font_size;
opener.document.getElementById("text_location").value = text_location;
opener.document.getElementById("color").value = ncolor;
self.close();
return false;
}

dave487
Oct 26th 2005, 4:38 am
I do this with the following script, it works in IE:

Main page:

<form>
<input type=button name=choice onClick="window.open('page.php3','popuppage','width=850,toolbar=1,resizable=1,scrollbars=yes,height=700,top=100,left=100');" value="Select from Database">
</form>


Popup page:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function sendValue<?php echo "" . $data['id'] . ""; ?>(s){
var selvalue = s.value;
window.opener.document.form.details.value = selvalue;
window.opener.document.form.id.value = <?php echo "" . $data['id'] . "";?>;
window.close();
}
// End -->
</script>
<form name="selectform<?php echo "" . $data['id'] . "";?>">
<input type="hidden" name="details" value="<?php echo "" . $data['name'] . "" ?> <?php echo "" . $data['address'] . "" ?> <?php echo "" . $data['phone'] . "" ?>">
<input type=button value="Copy to Form" onClick="sendValue<?php echo "" . $data['id'] . "";?>(this.form.details);">
</form>

FRYO
Oct 30th 2005, 10:52 am
Thanks for your help Dave but I dont think this is working with me.

Anybody else can help?

killer2021
Nov 11th 2008, 4:29 pm
Not working for me either :(

rene7705
Nov 12th 2008, 12:41 am
Tested in IE and FF;

file t1.html

<!--compatibility mode-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<form>
<input id="details" name="details">
<input type="button" name="choice" onClick="window.open('t2.html','popuppage','width=850,toolbar=1,resizable=1,scrollbars=yes,height=700,top=100,left=100');" value="Open popup">
</form>
</body>
</html>


file t2.html:

<!--compatibility mode-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function sendValue (s){
var selvalue = s.value;
window.opener.document.getElementById('details').value = selvalue;
window.close();
}
// End -->
</script>
<form name="selectform">
<input name="details" value="">
<input type=button value="Copy input to parent opener" onClick="sendValue(this.form.details);">
</form>

</body>
</html>


Note that if you run this from your local harddrive, IE will likely display an activeX warning. This doesn't happen when you put it on a webserver.

Varsys Inc.
Dec 8th 2008, 2:37 pm
That works. Thanks for helpful info.

chxxangie
Jan 14th 2009, 9:29 am
how to get the pop window value to the frame in parent window?
thanks in advance...

baybossplaya
Feb 11th 2009, 2:32 am
<!--compatibility mode-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function sendValue (s){
var selvalue = s.value;
window.opener.document.getElementById('details').value = selvalue;
window.close();
}
// End -->
</script>
<form name="selectform">
<input name="details" value="">
<input type=button value="Copy input to parent opener" onClick="sendValue(this.form.details);">
</form>

</body>
</html>

mudassar anwar
May 3rd 2009, 1:57 am
is this code still work?

yantomulia
May 28th 2009, 5:14 am
very old thread, is it still work?