I was advised by one person to use the .selectedIndex as a pointer to an array that contains the descriptions. However, I'm not sure how to do this.
Script in action: http://70.84.139.154/~devsite/script_for_forum.php
Code: Select all
<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 txtValueObj = document.getElementById('partNo1');
var txtTextObj = document.getElementById('desc1');
var selIndex = selObj.selectedIndex;
txtTextObj.value = selObj.options[selIndex].text;
}
</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);
while ($item = mysql_fetch_array($result))
{
$partnum=$item["partnum"];
$description=$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>";
?>
</body>
</html>