...

View Full Version : putting checked values into a var to send to parent window



ShamanFR
09-21-2005, 12:43 PM
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

nikkiH
09-21-2005, 02:30 PM
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;

ShamanFR
09-22-2005, 09:39 PM
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:

<?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:

<?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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum