Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Location
    Paris, France
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question putting checked values into a var to send to parent window

    Ok I have a pop up window that comes up with a list of icheckbox and I wanted to know how I can get all the checked items put into a variable to send back to the parent window apon clicking on a done button? Lets say I have a list of colors for example. Red, Green, Blue, Yellow, Black and I check Red, Blue, Yellow is there a way to get the values of the checked items into a var to send to the parent wind?

    Nick
    Last edited by ShamanFR; 09-23-2005 at 12:32 AM.

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    You don't need them in a variable to send them to the parent.
    That is, if the parent really IS the parent (opened the popup), the popup (child) can access hidden form fields and variables in the parent simply by using the self.opener object.

    i.e. to set parent form field value to a child's form field value, from the child, use

    self.opener.document.formname.elementname.value=
    document.formname.elementname.value;

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New to the CF scene
    Join Date
    Sep 2005
    Location
    Paris, France
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok I actually found out how to do what I wanted ot do, but now I need to figure out something else. I have the checkbox list but I also want to send a hidden value for each selected checkbox, how can I do that?

    Here is my code.

    Popup window:
    Code:
    <?php
    require_once "connect.php";
    ?>
    <html>
    <head>
    <title>Critter Mountain Wear ... Enjoy :P</title>
    <META HTTP-EQUIV="imagetoolbar" CONTENT="no">
    <meta name="description" content="Critter Mountain Wear - Paragliding Equipment">
    <meta name="keywords" content="Critter, Critter Mountainwear, Critter Mountain Wear, Critter Harness, Harness, Competition, Competition Harness, Anarchy Pro, Anarchy, Cockpit, Instrument Container, Harnesses, Colorado Harnesses, Paragliding Harnesses, Paragliding World, Tandem Harness, Paragliding Equipment, Equipment, Product Comparision">
    <link href="style.css" rel="stylesheet" type="text/css">
    <script language="JavaScript"> 
    <!--Begin
    // Add the selected items in the parent by calling method of parent
    function addToParentWin() {
    var arrColours = new Array();
    var allBoxes = document.body.getElementsByTagName("input");
    for(var i = 0; i < allBoxes.length; i++){
     if(allBoxes.item(i).type == 'checkbox' && allBoxes.item(i).checked){
      arrColours[arrColours.length] = allBoxes.item(i).value;
     }
    }
    
    window.opener.itemsForm.colors.value=arrColours.join(", ");
    window.close();
    }
    function changeBox(cbox) {
    box = eval(cbox);
    box.checked = !box.checked;
    }
    // End -->
    </SCRIPT>
    </head>
    
    <body>
    
    <center>
    <form method='post' name='formColors'>
    <table width='200' cellpadding='0' cellspacing='0' style='border: 1px solid #3f4d1e; border-bottom: 0px;'>
    <tr bgcolor='#898989'>
    <td align='center' valign='middle' width='200' style='border-bottom: 1px solid #3f4d1e; padding: 4px 0px;'><a class="categorie"><b> COLORS LIST </b></a></td>
    </tr>
    
    <?php
    	$get = mysql_query("SELECT color, colorImg, idColor FROM critter_colors ORDER BY color ASC") or die(mysql_error());
    	
    	$color1 = "#dcdcdc";
    	$color2 = "#eeeeee";
    	$class1 = "colors2";
    	$class2 = "colors1";
    	
    	$count=0;
    	$i=0;
    	while($r = mysql_fetch_array($get)){
    		$color = $r['color'];
    		$colorImg = $r['colorImg'];
    		$idColor = $r['idColor'];
    		if($row_counter & 1){
    			$bg_color = $color1;
    			$class = $class1;
    		}else{
    			$bg_color = $color2;
    			$class = $class2;
    		}
    		$row_counter++;
    		
    		echo("
    
    <tr bgcolor='$bg_color'>
    <td align='left' valign='bottom' width='200' style='border-bottom: 1px solid #3f4d1e; padding: 2px 0px 2px 0px;'><a href='#' onClick=\"this.blur(),changeBox('document.formColors.choice$i');return false;\" class='$class'><img src='itemcolors/$colorImg' height='25' width='25' alt='ash' border='0'> &nbsp;<input type='checkbox' name='choice$i' value='$color'> $color </a></td>
    </tr>
    ");
    	$i++;
    	}// end while loop
    ?>
    <tr>
    <td align='center' style='border-bottom: 1px solid #3f4d1e; padding: 5px 2px;'><input type='button' value='ADD COLORS' onClick='addToParentWin()' class='itemsbt'></td>
    </tr>
    </table>
    </form>
    </center><BR>
    
    
    </body>
    </html>
    Parent window:
    Code:
    <?php
    include "connect.php";
    ?>
    <hmtl>
    <head>
    <title>Critter Mountain Wear ... Enjoy :P</title>
    <META HTTP-EQUIV="imagetoolbar" CONTENT="no">
    <meta name="description" content="Critter Mountain Wear - Paragliding Equipment">
    <meta name="keywords" content="Critter, Critter Mountainwear, Critter Mountain Wear, Critter Harness, Harness, Competition, Competition Harness, Anarchy Pro, Anarchy, Cockpit, Instrument Container, Harnesses, Colorado Harnesses, Paragliding Harnesses, Paragliding World, Tandem Harness, Paragliding Equipment, Equipment, Product Comparision">
    <link href="style.css" rel="stylesheet" type="text/css">
    <SCRIPT LANGUAGE="JavaScript">
    function small_window(myurl) {
    var newWindow;
    var props = 'scrollBars=yes,resizable=yes,toolbar=no,menubar=no,location=no,directories=no,width=300,height=450';
    newWindow = window.open(myurl, "Add_from_Src_to_Dest", props);
    }
    </script>
    </head>
    
    <body>
    
    	<center>
    	<table width='650' cellapdding='0' cellspacing='0' border='0'>
    	<form method='post' action='itemsform.php?option=process' enctype='multipart/form-data' name="itemsForm">
    	<tr>
    	<td width='10'></td>
    	<td width='190' align='left'>&nbsp;<img src='imgs/navbar_arrows.jpg' border='0'><a class='txt'> Item Colors ...</a></td>
    	<td width='450' align='left'><input type='text' name='colors' size='50' class='itemsform'> <input type='button' value='Add Colors' onclick =\"javascript:small_window('itemcolors.php');\" class='itemsbt'> </td>
    	</tr>
    </table>
    </center>
    
    </body>
    </html>

    Nick


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •