1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Passing variables from pop-up window to parent window.

Discussion in 'JavaScript' started by FRYO, Oct 25, 2005.

Thread Status:
Not open for further replies.
  1. #1
    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;
    	}
    Code (markup):
     
    FRYO, Oct 25, 2005 IP
  2. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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>
    
    HTML:
    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>
    
    HTML:
     
    dave487, Oct 26, 2005 IP
  3. FRYO

    FRYO Well-Known Member

    Messages:
    220
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    118
    #3
    Thanks for your help Dave but I dont think this is working with me.

    Anybody else can help?
     
    FRYO, Oct 30, 2005 IP
  4. killer2021

    killer2021 Peon

    Messages:
    872
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Not working for me either :(
     
    killer2021, Nov 11, 2008 IP
  5. rene7705

    rene7705 Peon

    Messages:
    233
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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>
    
    Code (markup):
    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>
    
    Code (markup):
    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.
     
    rene7705, Nov 12, 2008 IP
  6. Varsys Inc.

    Varsys Inc. Peon

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    That works. Thanks for helpful info.
     
    Varsys Inc., Dec 8, 2008 IP
  7. chxxangie

    chxxangie Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    how to get the pop window value to the frame in parent window?
    thanks in advance...
     
    chxxangie, Jan 14, 2009 IP
  8. baybossplaya

    baybossplaya Active Member

    Messages:
    597
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    58
    #8
    <!--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>
    Code (markup):
     
    baybossplaya, Feb 11, 2009 IP
  9. mudassar anwar

    mudassar anwar Well-Known Member

    Messages:
    757
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    110
    #9
    is this code still work?
     
    mudassar anwar, May 3, 2009 IP
  10. yantomulia

    yantomulia Peon

    Messages:
    57
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    very old thread, is it still work?
     
    yantomulia, May 28, 2009 IP
Thread Status:
Not open for further replies.