Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing multiple variables to parent window

Status
Not open for further replies.

ShamanFR

Programmer
Sep 20, 2005
9
FR
Ok I have an itme page with a popup window conaining a list of colors. After checking the colors wanted you hit add and it adds it to the text field in the parent form. Now I wanted to know if there was a way to send a hidden field to the parent field. Lets say I have the color name being sent, I would also like to send the name of the img in a hidden field for each check box. How can I get that.

Here is my script in case someone can help me do this.

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>

Thanks,

Nick
 
After checking the colors wanted you hit add and it adds it to the text field in the parent form. Now I wanted to know if there was a way to send a hidden field to the parent field.

You already know how to set field values in your parent form - why not have a hidden field already in it, and just set the value of it? Why bother with creating an extra input dynamically?

Dan


[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Well because the hidden field value will be filled with the img names of each color. I have been racking my brain for about 2 days to figure out a way to do this, and this seems to be the best.

What I have going on now is, I select and enter the colors in the color field like so (Green, Yellow, Blue, Black) Then when i go to the item and view the item, the colors are seperated from (Green, Yellow, Blue, Black) Into a dropdown menue for the shopping cart, and into individual variables to display the color image. The only thing is that I don't know how to pull out the image name for each color name from the db.

This i why I need to dynamically add the img name in a hidden field for each color.

Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top