Lius 0 Newbie Poster
function populateHarga() {
var x=document.getElementById("barang").value;
document.getElementById("harga").value=x;  
var y=document.getElementById('barang')[document.getElementById('barang').selectedIndex].innerHTML;
document.getElementById("nama_brg").value=y;
}
function populateTotal()
{
var y=document.getElementById("jumlah").value;
var x=document.getElementById("harga").value;
document.getElementById("totalnya").value=x*y;
}
</script>
<html>
<body>
<?php 
include ("db.php");
$now=date("Y-m-d",time());
?>
<?
if($_REQUEST['action']=="del")
	{
		mysql_query("DELETE FROM temp WHERE t_no={$_REQUEST['id']};");
	}
	
?>
<table border="0">
  <tr>
  	<td>No.Faktur</td>
	<td><? echo "$no";?></td>
	<td></td>
	<td>Tanggal Order</td>
	<td><? echo "$now";?></td>
	</tr>
	<tr>
    <td>Atas Nama </td>
    <td><input name="nama" id="an" type="text" maxlength="25" /></td>
	<td></td>
  
    <td>Tanggal Kirim</td>
    <td> <input id="tgl_pakai" name="tgl_pakai" type="text" /></td>
  </tr>
   
  <tr>
    <td valign="top">Alamat</td>
    <td><textarea name="alamat" cols="50" rows="5" /></textarea ></td>
  </tr>
</table>
<?php 
//Request
				$nama_b=$_GET['nama_brg'];
				$harga_b=$_GET['harga'];
				$jumlah_b=$_GET['jumlah'];
				$total_b=$_GET['totalnya'];
				if($nama_b!="")
				{
				if($jumlah_b=="")$t_jumlah=1;
				mysql_query("INSERT INTO temp(`t_nama`,`t_harga`,`t_jumlah`,`t_total`) VALUES('$nama_b','$harga_b','$jumlah_b','$total_b')");
				}


//form
$get = mysql_query("select * from inventori");

echo"<table width=649 border=0 cellspacing=3 cellpadding=3>";
echo"<form action=NewT.php method=get name=transaksi id=transaksi>";
echo"<tr>";
echo"<td width=99>Nama Produk</td>";
echo"<td width=198><select id=barang name=barang onchange=populateHarga() />";
echo "<option></option>";
// Here the problem is maybe i should add a variable but i dont know how. 
while($list=mysql_fetch_array($get))
{
echo "<option value='$list[harga]' >$list[nama_barang]</option>";
}
echo"</select></td>";
echo"</tr>";
echo"<tr>";
echo"<td>Jumlah</td>";
echo"<td><input align=right id=jumlah name=jumlah type=text size=12 onblur=populateTotal() /></td>";
echo"</tr>";
echo"<tr>";
echo"<td>Harga</td>";
echo"<td>";
echo"<input id=harga name=harga type=text />";
echo"</td>";
echo"</tr><tr><td>";
echo"Total :";
echo"</td><td>";
echo"<input type=text name=totalnya id=totalnya  /> </td></tr>";
echo"<input type=hidden id=nama_brg name=nama_brg />";
echo"<tr>";
echo"<td colspan=2><div align=right><input name=Next type=submit  value=Next />
  <input name=batal type=reset id=batal value=Reset />
</div></td></tr>";
echo"</table></form>";

//tampilkan temp tabel
$itung = mysql_query("select count(t_no) from temp");
if($itung>0){
echo "<table borger=1>";
echo "<tr><td>";
echo "<th>"."Nama";
echo "<th>"."Jumlah";
echo "<th>"."Harga";
echo "<th>"."Total";
echo "<th>"."</th>";
echo "</div></td></tr>";
$hasil= mysql_query("select * from temp");
while($row=mysql_fetch_array($hasil))
{
echo "<tr><td><th>";
echo $row[t_nama]."</th>";
echo "<th>";
echo $row[t_jumlah]."</th>";
echo "<th>";
echo $row[t_harga]."</th>";
echo "<th>";
echo $row[t_total]."</th>";
echo "<th>";
echo "<a onclick=\"return confirm('"."Apa anda yang ingin menghapus ?"."');\" href=NewT.php?action=del&id=".$row[t_no]."><img src=delete-icon.png width=10 heigth=10></a></th>";
}}
?>

<form name=cloud method=get action=print.php> 
<input id=nama_s name=nama_s type=hidden />
<input id=kirim_s name=kirim_s type=hidden />
<input id=alamat_s name=alamat_a type=hidden />
<input type="submit" name="Submit" value="Finish" />
</form>

</body> 
</html>

My problem is i want to get the maximum of stok in inventori where nama_barang is selected. and use it for the cap of jumlah that will be inputed by user. maybe with a javascript as well.. Sorry my english isnt good