what i want to do is create a dropdown box with fields from mysql and when the selection is changed the price get auto added to the field called price

it looks like this



PHP Code:
<?
$sql 
mysql_query("Select * from item") or die("error in sql " mysql_error());
?>

<form>
<select name="products" onchange="selectprice(this.form)">
<option name="0">select a product</option>
<?
while ($row mysql_fetch_array($sql))
{
$price $row["products_costprice"];
?>
<script>
function selectprice(theForm)
{

    theForm.price.value = '<? print $price?>';

}
</script>
<option name="<?=$row["id"]?>"><?=$row["itemcode"]?></option>
<?
}
?>
</select><br><br>
<input type="text" name="price">
</form>

this all work fine but it displays the wrong price i believe this is because i need know what product id has been selected from the item list.

looking at it ,it looks like i need to echo out the option name but how?... (theForm.products.option.name ???)

thx
nexe