cara menampilkan harga

_FB_NAME_ · Sep 17, 2012
gimana sich cara menampilkan harga secara otomatis
<tr>
			<td>Tindakan</td>  
			<td>
			<?
				$sql = "SELECT kode_tarif, nama_tarif, harga FROM jenis_tarif";
				$result = mysql_query($sql);

				echo "<select name='kode_tarif'>";
			while ($row = mysql_fetch_array($result)) {
				echo "<option value='" . $row['kode_tarif'] . "'>" . $row['nama_tarif'] ." - Rp.".$row['harga']. "</option>";
				}
				echo "</select>";
			?>
			</td>
		</tr>
		<tr>
			<td>Harga</td> 
			<td><input type="text" name="harga" id="harga"/></td>
		</tr>
pada input harga ketika di klik nama tarif??
Silahkan login untuk menjawab!
2
Loading...
ant · Sep 17, 2012 · 2 Suka · 0 Tidak Suka
Coba pakai ini :
<tr>
    <td>Tindakan</td>
    <td>
   <?php    
	include ('config.php'); // isinya adalah koneksi ke database
    $result = mysql_query("select kode_tarif, nama_tarif, harga FROM jenis_tarif");    
    $jsArray = "var prdName = new Array();\n";    
    echo '<select name="kode_tarif" onchange="changeValue(this.value)">';    
    echo '<option>--Pilih --</option>';    
    while ($row = mysql_fetch_array($result)) {    
        echo '<option value="' . $row['kode_tarif'] . '">' . $row['kode_tarif'] . '</option>';    
        $jsArray .= "prdName['" . $row['kode_tarif'] . "'] = {harga:'" . addslashes($row['harga']) . "'};\n";    
    }    
    echo '</select>';    
     ?>  
		
		</td>
    </tr>
	<script type="text/javascript"> 
   <?php echo $jsArray; ?>    
    function changeValue(id){  
	document.getElementById('prd_harga').value = prdName[id].harga; 
    };  
    </script>  
  <tr>
   
        <td><input type="text"  name="harga" id="prd_harga" /></td>
    </tr>