moohon bantuanya...
saya mau menampilkan data dari combobox ke textbox, yang satunya muncul tapi yang satu lagi gak muncul, tolong bantuannya
<?php
mysql_connect("localhost","root","");
mysql_select_db("koperasi");
$result = mysql_query("select * from kecamatan");
$jsArray = "var kecamatan = new Array();\n";
echo 'Kode Kecamatan : <select name="kode_kecamatan" onchange="changeValue(this.value)">';
echo '<option>-------</option>';
while ($row = mysql_fetch_array($result)) {
echo '<option value="' . $row['kode_pos'] . '">' . $row['kode_pos'] . '</option>';
$jsArray .= "kecamatan['" . $row['kode_pos'] . "'] = {name:'" . addslashes($row['nama_kecamatan']) . "'};\n";
}
echo '</select>
Nama Kecamatan : <input type="text" name="kecamatan" id="tampil_kecamatan"/>';
?>
<?php
$result = mysql_query("select * from agama");
$jsArray1 = "var agama = new Array();\n";
echo 'Kode Agama : <select name="kode_agama" onchange="changeValue(this.value)">';
echo '<option>-------</option>';
while ($row = mysql_fetch_array($result)) {
echo '<option value="' . $row['id_agama'] . '">' . $row['id_agama'] . '</option>';
$jsArray1 .= "agama['" . $row['id_agama'] . "'] = {name:'" . addslashes($row['nama_agama']) . "'};\n";
}
echo '</select>
Agama : <input type="text" name="agama" id="tampil_agama"/>';
?>
<script type="text/javascript">
<?php echo $jsArray; $jsArray1; ?>
function changeValue(id){
document.getElementById('tampil_kecamatan').value = kecamatan[id].name;
document.getElementById('tampil_agama').value = agama[id].name;
};
</script>