silahkan di pelajari script ini gan, kasusnya hampir sama dengan punya agan
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("klinik");
$result = mysql_query("select * from tbl_pemeriksaan");
$jsArray = "var prdName = new Array();\n";
echo '<center>Noreg:<select name="prdId" onchange="changeValue(this.value)">';
echo '<option>-------</option>';
while ($row = mysql_fetch_array($result)) {
echo '<option value="' . $row['no_pemeriksaan'] . '">' . $row['no_pemeriksaan'] . '</option>';
$jsArray .= "prdName['" . $row['no_pemeriksaan'] . "'] = {name:'" . addslashes($row['tgl_pemeriksaan']) . "',anam:'".addslashes($row['anamnesa'])."',dial:'".addslashes($row['diagnosa'])."',peny:'".addslashes($row['nama_penyakit'])."'};\n";
}
echo '</select>';
?>
<br>
<br>
Tgl Periksa: <input type="text" name="prod_name" id="prd_name"readonly/>
<br>
<br>
Anamnesa: <input type="text" name="prod_anam" id="prd_anam"readonly/>
<br>
<br>
Diagnosa: <input type="text" name="prod_dial" id="prd_dial"readonly/>
<br>
<br>
Penyakit: <input type="text" name="prod_peny" id="prd_peny"readonly/>
<script type="text/javascript">
<?php echo $jsArray; ?>
function changeValue(id){
document.getElementById('prd_name').value = prdName[id].name;
document.getElementById('prd_anam').value = prdName[id].anam;
document.getElementById('prd_dial').value = prdName[id].dial;
document.getElementById('prd_peny').value = prdName[id].peny;
};
</script>