hello i’m a noob to all this and i was wondering how to automatically populate form fields based on what a user chooses in a combo box. what i would like is when a user chooses a branch from the combo box, the phone and fax numbers pertaining to that particular branch are automatically displayed in the corresponding text field. the data behind the combo box and the 2 fields i want populated all come from the same table in a mysql database. any help in this is much appreciated, thanks! here is my code so far:
[code=php]<?php require_once(‘../Connections/Directory.php’); ?>
<?php
mysql_select_db($database_Directory, $Directory);
$query_rsBranches = “SELECT * FROM branches”;
$rsBranches = mysql_query($query_rsBranches, $Directory) or die(mysql_error());
$row_rsBranches = mysql_fetch_assoc($rsBranches);
$totalRows_rsBranches = mysql_num_rows($rsBranches);
?>
<html>
<head>
<title>help me</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
</head>
<body leftmargin=”0″ topmargin=”0″ marginwidth=”0″ marginheight=”0″>
<table width=”600″ border=”1″ align=”center” cellpadding=”5″ bordercolor=”#BFC3EB” bgcolor=”#FFFFFF”>
<tr>
<td class=”h1″><p> </p>
<form action=”” method=”post” name=”dirInsert” id=”dirInsert”>
<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td width=”10%”>Last Name</td>
<td width=”25%”><input name=”txtLast” type=”text” id=”txtLast2″></td>
<td width=”12%”> </td>
<td width=”41%”> </td>
<td width=”2%”> </td>
<td width=”10%”> </td>
</tr>
<tr>
<td>First Name</td>
<td><input name=”txtFirst” type=”text” id=”txtFirst”></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Branch</td>
<td><select name=”selectBranch” id=”selectBranch”>
<?php
do {
?>
<option value=”<?php echo $row_rsBranches[‘branch_name’]?>”><?php echo $row_rsBranches[‘branch_name’]?></option>
<?php
} while ($row_rsBranches = mysql_fetch_assoc($rsBranches));
$rows = mysql_num_rows($rsBranches);
if($rows > 0) {
mysql_data_seek($rsBranches, 0);
$row_rsBranches = mysql_fetch_assoc($rsBranches);
}
?>
</select> </td>
<td>Phone</td>
<td><input name=”txtPhone” type=”text” id=”txtPhone”></td>
<td>Fax</td>
<td><input name=”txtFax” type=”text” id=”txtFax”></td>
</tr>
<tr>
<td>Title</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</form>
<p> </p>
<p align=”right”> </p></td>
</tr>
</table>
<div align=”right”><br>
<br>
<br>
<br>
<br>
</div>
</body>
</html>
<?php
mysql_free_result($rsBranches);
?>