Below is the code I use to populate a textboxes (compaddress) when I select the compname from the dropdown.
I would like to be able to populate other textboxes such as the compdescription, compmaincontact and others when I select the compname from the dropdown.
I think that I need an array but I really would like some advice on how to do it as all of my attempts have failed so far
appreciate any help you can give!
<script type="text/javascript">
function showname(what)
{
what.form.textfield.value=what.options[what.selectedIndex].title
}
window.onload=function() {
showname(document.form1.number)
}
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title> Untitled Document</title>
</head>
<body>
<form>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mct", $con);
//Query
$query1 = "SELECT * FROM company ".
"ORDER BY compname ";
$result1 = mysql_query($query1) or die(mysql_error());
//$result = mysql_query ($query);
echo "<select name=\"compid\" onchange=\"showname(this)\">";
// printing the list box select command
while($row1=mysql_fetch_array($result1)){
echo "<option value=\"$row1[compid]\" title=\"$row1[compaddress]\">$row1[compname]</option>";
//echo "<option value=\"$row1[compid]\" title=\"$row1[compdescription]\">$row1[compname]</option>";
}
echo "</select>";// Closing of list box
?>
<label>
<input type="text" name="textfield" value="" />
<input type="text" name="textfield2" value="" />
</label>
<input name="submit" type="submit" id="submit" value="Aceptar" />
</form>
</body>
</html>