<?php
	include "connect.php";
 
	$jsArray1 = "var idxspp = new Array();\n";
	$jsArray2 = "var idxdpp = new Array();\n";
	echo "<table width='60%' border='1'>
			<tr><td>Nama </td><td>SPP</td><td>DPP</td></tr>
			<tr>
				<td><select name='uv' id='uv' onchange='document.getElementById(\"spp\").value = idxspp[this.value]'>
					<option value='0'>Pilih </option>";
					$tampil=mysql_query("SELECT * FROM coba ORDER BY nama");
					while($r=mysql_fetch_array($tampil)){
					echo "<option value=$r[id_coba]>$r[nama]</option>";
					$jsArray1 .= "idxspp['" . $r[id_coba] . "'] = '" . addslashes($r['SPP']) . "' ;\n";
					$jsArray2 .= "idxdpp['" . $r[id_coba] . "'] = '" . addslashes($r['DPP']) . "' ;\n";
 
            }
    echo "  		</select>
				</td>
				<td><input type=text name='spp' id='spp'></td>
				<td><input type=text name='dpp' id='dpp'></td>
			</tr>";
	echo "	
			</table>";
	?>
	<script type="text/javascript"> 
	<?php echo "$jsArray1 $jsArray2 ";?>
 
    </script>
Silahkan login untuk menjawab!
0
Loading...
adit · Dec 31, 2014 · 0 Suka · 0 Tidak Suka
coba ni
<?php    
mysql_connect("localhost","root","");    
mysql_select_db("dbgestun");    
$result = mysql_query("select * from edc");    
$jsArray = "var prdName = new Array();\n";    
echo 'Kode EDC : <select name="prdId" onchange="changeValue(this.value)">';    
echo '<option>--Silahkan Pilih --</option>';    
while ($row = mysql_fetch_array($result)) {    
    echo '<option value="' . $row['id_edc'] . '">' . $row['id_edc'] . '</option>';    
    $jsArray .= "prdName['" . $row['id_edc'] . "'] = {name:'" . addslashes($row['nama_edc']) . "',desc:'".addslashes($row['bankRT_trans'])."'};\n";    
}    
echo '</select>';    
?>     
Nama EDC Machine : <input type="text" name="nama_edc" id="nama_edc"/>   
Bankrate : <input type="text" name="bankRT_trans" id="bankRT_trans"/>  
<script type="text/javascript">    
<?php echo $jsArray; ?>  
function changeValue(id){  
document.getElementById('nama_edc').value = prdName[id].name;  
document.getElementById('bankRT_trans').value = prdName[id].desc;  
};  
</script>