1st, please look at the script in action to help illustrate what I am trying to do:
http://70.84.139.154/~devsite/test_script.php
When a user selects an option in the pull-down menu, I want the description to be printed in the text box. Anyone know how I can do this? This is the code I have so far:
<html>
<head>
<title> Work Order System</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script language="JavaScript">
function showSelected1()
{
var selObj = document.getElementById('partNo1');
var txtTextObj = document.getElementById('desc1');
var selIndex = selObj.selectedIndex;
txtTextObj.value = Descriptions[selObj.options[selIndex].value];
}
</script>
</head>
<body>
<?php
include ("common_vars.php");
mysql_connect("$DB_HOSTNAME1", "$DB_USERNAME1", "$DB_PASSWORD1") or die
("Could not connect to Server".mysql_error());
mysql_select_db("$DB_NAME1") or die ("Unable to select database".mysql_error());
echo "<form name='add_form'>";
echo "<select name='partNo1' size='1' onChange='showSelected1()' class='style10'>";
echo"<option selected value='' class='style10'> </option>";
$query = "SELECT * from sunparts";
$result = mysql_query($query);
$description = array();
while ($item = mysql_fetch_array($result))
{
$partnum=$item["partnum"];
$description[$item['partnum']] =$item["description"];
echo"<option value='$partnum' class='style10'>$partnum</option>";
}
echo "</select>";
echo " <input name='desc1' type='text' class='style10' id='desc1' size='40'>";
echo "</form>";
echo "<script type=\"text/javascript\">
var Descriptions = new Array();\n";
foreach ($description as $key => $value)
{
echo "Descriptions[\'$key\'] = \'$value\'\n";
}
echo '</script>';
?>
</body>
</html>