[SOLVED] Populating text areas with a value from a combo box

JavaScript and client side scripting.

Moderator: General Moderators

jamesloi
Forum Newbie
Posts: 15
Joined: Thu Jul 15, 2004 5:11 am
Location: London

Post by jamesloi »

Ok i still cant get it to work ..so heres my code

orderConfirm.php

Code: Select all

<?php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-UK">
<head>
<title>Order Confirmation</title>
<meta http-equiv="Expires" content="Fri, 21 May 2004 00:00:00 GMT"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="Author" content="J.Loi"/>
<link rel="stylesheet" type="text/css" href="style/style.css" />
</head>

<body>
	<form name="supplier" method="post" action="orderCAdd.php" enctype="application/x-www-form-urlencoded">	

	<?php

	require '/content/StartupHostPlus/z/e/www.zensystems.net/web/paper/mysql.php';
	
	global $HTTP_GET_VARS;

	$reference = $HTTP_GET_VARS["ref"];

	?>

	<!--############################################################ left sidebar ############################################################-->

	<div id="left" class="sidebar">
		<div class="box">
			<span class="boxBorder boxTab">Booking Main</span>
			<div class="boxBorder boxMain">
			
				<a href="initial.php">Initial Booking</a><br />
				<a href="enter.php">Enter Booking</a><br />
				<a href="admin.php">Administrator</a><br />

			</div>
		</div>
		<br />
	</div>

	<!--############################################################ middle bar ############################################################-->

	<div id="middle">
	<font color="blue">
	<table style="width:100%;">
		<tr>
			<td class="textMiddle">
				<a class="floatLeft" onclick="top.location.href='pass.php'" onmouseover="style.cursor='pointer'" onmouseout="style.cursor='default'">
					<span class="zs lightRed">[</span>
					<span class="zs darkRed">PAPER ADMIN PAGE</span>
					<span class="zs lightRed">]</span>
				</a>
			</td>

		</tr>
	</table>
	<br />
		<!-- PARAGRAPH HEADER -->
		<table class="paragraphHeader" cellspacing="0" cellpadding="0">
			<tr style="vertical-align:bottom;">
				<td class="big "><font color="black">Order Confirmation</font></td><br />
			</tr>
		</table>
		<!-- PARAGRAPH -->
		<div class="paragraph">
		</div><br /><hr /><br />
		<!-- PARAGRAPH HEADER -->
		<table class="paragraphHeader" cellspacing="0" cellpadding="0">
			<tr style="vertical-align:bottom;">
				<td class="large"><font color="red">Booking Ref: </font><font color="blue"><?php echo $reference ?></font></td><br />
			</tr>
		</table>
		<br />
	<table width="100%" height="210">
	  <tr>
		<td height="100" class="boxBorder" width="100%">

		<?php 

			mysql_connect($host, $user, $passwd) or die(MySQL_Error()); 
			mysql_select_db($dbName) or die(MySQL_Error()); 

			$sql="SELECT * FROM Supplier";  
			$result=mysql_query($sql); 

			echo "&nbsp;&nbsp;&nbsp;<select name="mySelect" size="1"><option style="color: blue" value="opt1" >Supplier</option>";

			while ($rows=mysql_fetch_array($result)){

				$option= $rows['Supplier_ID'];
				$option2= $rows['Name'];

				echo ("<option style="color: blue" onClick="javascript:query_my_db('.$option.');" value="$option">$option&nbsp;&nbsp;&nbsp; $option2</option>");
			}
			echo "</select><br/><br/>";
			
		?>

		&nbsp;&nbsp;&nbsp;<textarea rows=5 cols=30 wrap="virtual" name="summary"></textarea>
		
		</td>
	  </tr>
	</table>

	</font>
	<br /><br /><hr /><br />

	<input class="a" type="submit" name="Sub" value="Add Booking" onmouseover="style.cursor='pointer'" onmouseout="style.cursor='default'"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="reset" value="Reset Form" onmouseover="style.cursor='pointer'" onmouseout="style.cursor='default'"/>

	<hr />
	</div>
	<div class="full centered small"><br /><br /><br /><br />Site by <a href="http://www.zensystems.net">Zen Systems Ltd</a><br /><img src="pictures/logo.gif" width="80" height="60" alt="logo" ></div>

	<frame name="MyPHPPageFrame" style="width:0px; height:0px; border:0px" scrolling="no" src=""> 
</body>

<script language="javascript"> 

function populate_them_all(SupplierID, Name, Adress1, Adress2, Postcode) 
{ 
   document.supplier.summary.value = 'Supplier ID : ' + SupplierID + '\n' + 'Name : ' + Name + '\n' + 'Address1 : ' + Adress1 + '\n' + 'Adress 2 : ' + Adress2 + '\n' + 'Postcode : ' + Postcode; 
} 
function query_my_db(mySupplierSelection) 
{ 
   MyPHPPageFrame.location.replace('querySupplierScript.php?selection='+mySupplierSelection); 
} 

</script> 
</form>
</html>

?>
querySupplierScript.php

Code: Select all

<?php
<?php 
$val = $HTTP_GET_VARS['selection']; 

mysql_connect($host, $user, $passwd) or die(MySQL_Error()); 
mysql_select_db($dbName) or die(MySQL_Error()); 

$sql = "SELECT * FROM Supplier WHERE Supplier_ID = '".$val."'"; 

$result = mysql_query($sql) or die(MySQL_Error()); 
$row = mysql_fetch_assoc($result); 

$supplierid = $row['Supplier_ID']; 
$Name = $row['Name']; 
$address1 = $row['Address 1']; 
$address2 = $row['Address 2']; 
$postcode = $row['Posctcode']; 

?> 

<script language="javascript"> 
function doit()
{ 

   var SupplierID = '<?php echo $supplierid; ?>'; 
   var Name = '<?php echo $name; ?>'; 
   var Adress1 = '<?php echo $adress1; ?>'; 
   var Adress2 = '<?php echo $address2; ?>'; 
   var Postcode = '<?php echo $postcode; ?>'; 

   window.parent.populate_them_all(SupplierID, Name, Adress1, Adress2, Postcode); 
} 
window.onload = doit; 
</script> 
?>
I am getting javascript errors but dont know why
jamesloi
Forum Newbie
Posts: 15
Joined: Thu Jul 15, 2004 5:11 am
Location: London

Post by jamesloi »

THANKS to people who replied to this thred..

I have solved this problem now. If anyone needs to know how to do this then i can tell you how. :D
Post Reply