mas, gimana sih script untuk tombol add saya ini. jadi saya mau, kalau d klik button add, maka combobox berisi data dari tabel barang dan apabila dipilih salah satu kodenya tampil juga nama barang dan harga. saya bingung nih mas. ini script'a:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
function combo(){
include"koneksi.php";
$result = mysql_query("select * from barang");
$jsArray = "var prdName = new Array();\n";
echo '<tr><td><select name="prdId[0]" onchange="changeValue(this.value)">';
echo '<option>-------</option>';
while ($row = mysql_fetch_array($result)) {
echo '<option value="' . $row['0'] . '">' . $row['0'] . '</option>';
$jsArray .= "prdName['" . $row['0'] . "'] = {name:'" . addslashes($row[1]) . "',desc:'".addslashes($row['2'])."'};\n";
}
echo '</select></td>';
?>
<td><input type="text" name="prod_name" id="prd_name"/></td>
<td><input type="text" name="prod_desc" id="prd_desc"/></td></tr>
<script type="text/javascript">
<?php echo $jsArray; ?>
<? echo" function changeValue(id){
document.getElementById('prd_name').value = prdName[id].name;
document.getElementById('prd_desc').value = prdName[id].desc;
};
</script>";
}
?>
<?
include"koneksi.php";
$query = "SELECT max(no_pembelian) AS akhir FROM detailpembelian WHERE no_pembelian like'$no%'";
$hasil = mysql_query($query);
$data = mysql_fetch_array($hasil);
$lastNo = $data['akhir'];
// baca nomor urut transaksi dari id transaksi terakhir
$lastNoUrut = substr($lastNo,6,1);
// nomor urut ditambah 1
$nextNoUrut = $lastNoUrut + 1;
// membuat format nomor transaksi berikutnya
$nextNo = TB."-".sprintf('%04s', $nextNoUrut);
echo"<form action=simpanpembelian.php method=post>
<table>
<tr><td>No Pembelian : <input type=text name=nop><input type =button value ='Auto No' onClick =this.form.nop.value='$nextNo'></td></tr>";?>
<?php
$result = mysql_query("select * from supplier");
$jsArray = "var nama_sup = new Array();\n";
echo '<tr><td><select name="kode_sup[0]" onchange="document.getElementById(\'name_sup\').value = nama_sup [this.value]">';
echo '<option>-------</option>';
while ($row = mysql_fetch_array($result)) {
echo '<option value="' . $row[0] . '">' . $row[0] . '</option>';
$jsArray .= "nama_sup ['" . $row[0] . "'] = '" . addslashes($row[1]) . "';\n";
}
echo '</select></td>';
?>
<td><input type="text" name="nama_supplier" id="name_sup"/></td>
<?echo combo();
?>
<script type="text/javascript">
<?php echo $jsArray;
?>
</script><td><button type="button" class="del">Del</button></td>
</tr>
<tr id="last">
<td colspan="4" align="right"><button type="button" id="addRow">Add</button></td>
</tr>
</table>
<input type="submit" value="Simpan"/>
</form>
<?php
include"koneksi.php";
//mengambil kode barang yang ada di database
$kode = mysql_query("SELECT *FROM barang");
while($p=mysql_fetch_array($kode)){
echo "<option value=$p[1]>$p[1]</option>";
$h=$p[0];
}
?>
</select>
<script type="text/javascript" src=" https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
var i = 1;
$(function(){
$("#addRow").click(function(){
row = '<tr>'+
'<td></td>'+
'<td><button type="button" class="del">Del</button></td>'+
'</tr>';
$(row).insertBefore("#last");
i++;
});
});
$(".del").live('click', function(){
$(this).parent().parent().remove();
});
</script>
</body>
</html>
terima kasih sebelum'a...