Fill value of text field based on dropdown

What im trying to do is for each item selected from the drop down, display its value in a text box (GAC). I have attached a picture of the image to clarify.

The drop down items are populated from a database, and each item has an associated GAC value. The remaining inputs are user supplied and all the inputs including the drop down item and its value are is stored in a different table in the database.

try

html + php

 
<select name="mySel" id="mySel" onchange="showValue(this,elemId)">
<option value="0">Select</option>
 
<?php  
$query = select gac from myTable;
$rs = mysql_query($query, $conn);
while($row=mysql_fetch_assoc($rs)) {
      echo '<option value="'.row['gac'].'">'.row['gac'].'</option>';
}
@mysql_free_result($rs);
?>
 
</select>
<input type="text" name="myInp" id="myInp" />

javascript

 
function showValue(selO,elemId) {
       inpO = document.getElementById(elemId);
       inpO.value = (selO.selectedIndex == 0)? '' : selO.options[selO.selectedIndex].value;
}