Saya Mencoba menggabungkan antara combobox Dinamis dan Multiple Rows yang dari pertanyaan http://www.myphptutorials.com/questions/otomatis-penjumlahan_196.html, http://www.myphptutorials.com/tutorials/154/menyimpan-data-menampilkan-beberapa-tabel serta http://ask.myphptutorials.com/questions/view/104.

Bagaimana Caranya agar bisa setiap menambah rows jika user memilih combobox maka akan menampilkan data di 2 textboxt...
misal : user menambah rows dan memilih baju maka akan langsung keluar harga dan Quantity stock barang di masing2 textboxt agar dan bisa dikalikan dengan menghasilkan sub harga dan grand total...
Please mohon pencerahannya..

Table Penjualan
===============
-- phpMyAdmin SQL Dump
-- version 2.10.2
-- http://www.phpmyadmin.net
-- 
-- Host: localhost
-- Generation Time: Apr 12, 2013 at 02:38 AM
-- Server version: 5.0.45
-- PHP Version: 5.2.3

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

-- 
-- Database: `penjualan`
-- 

-- --------------------------------------------------------

-- 
-- Table structure for table `baju`
-- 

CREATE TABLE `baju` (
  `id` int(11) NOT NULL auto_increment,
  `nm_baju` varchar(30) NOT NULL,
  `hrg` int(11) NOT NULL,
  `jml_stock` int(11) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;

-- 
-- Dumping data for table `baju`
-- 

INSERT INTO `baju` VALUES (1, 'Baju MU', 19000, 20);
INSERT INTO `baju` VALUES (2, 'Baju Juventus', 30000, 30);
INSERT INTO `baju` VALUES (3, 'Baju Real Madrid', 35000, 40);
<?
include "koneksi.php";

echo "<script type='text/javascript'>";
echo "function startCalculate(){";
echo "interval=setInterval('Calculate()',10)";
echo "}";

echo "function Calculate(){\n";
echo "var total=0;\n";
for ($i=1; $i<=20; $i++){
echo "document.getElementsByName('Sub_totalharga[$i]')[0].value=(document.getElementsByName('harga[$i]')[0].value*document.getElementsByName('jumlah[$i]')[0].value).toFixed(0);\n";
echo "total+=parseFloat(document.getElementsByName('Sub_totalharga[$i]')[0].value);\n";
}
echo "document.getElementsByName('totalongkos_ptgbhn')[0].value=total.toFixed(0)\n";
echo "}";

echo "function stopCalc(){";
echo "clearInterval(interval)";
echo "}";
echo "</script>";
$jsArray1 = "var idxhrg1 = new Array();\n";
echo "<form name='form3' id='form3' method='post' action='lima.php'>
							<table border='1' width='90%'  cellspacing='0' cellpadding='3'>
							<tr><td align='center' width='20%'>Nama Baju</td>
								<td align='center' width='20%'>Harga Baju</td>
								<td align='center' width='20%'>Jumlah Beli (/ Pcs)</td>
								<td align='center' width='20%'>Stock (/ Pcs)</td>
								<td align='center' width='10%'>Sub Total Harga</td>
								<td align='center' width='10%'>Action</td>
							</tr>";
echo "	<tr id='last'>
		<td colspan='6' align='right'><button type='button' id='addRow'>Add Rows</button></td>
		</tr>
		<tr>
			<td colspan='4' align='center'>Grand Total harga</td>
			<td align='center'><input type='text' class='input-small' name='totalongkos_ptgbhn' id='totalongkos_ptgbhn' style='text-align:right'></td>
		</tr> 
		</table>
		<br>
		<input type='hidden' name='jum' value='$n'>
		<input type='submit' name='submit' value='Submit'>
	</form>";
?>
<script type="text/javascript" src=" jquery-1.7.2.min.js"></script>
<script type="text/javascript">
var i = 1;
$(function(){
$("#addRow").click(function(){
row = '<tr>'+
//Baju
'<td><select name="baju['+i+']" onchange="document.getElementById("\harga"\).value = idxhrg1[this.value] ? idxhrg1[this.value] : 0"> <option value="0">Pilih Item</option><?
			$tampil=mysql_query("SELECT * FROM baju");
			while($r=mysql_fetch_array($tampil)){
				  echo "<option value=$r[id]>$r[nm_baju]</option>";
				  	$jsArray1 .= "idxhrg1['" . $r[id] . "'] = '" . addslashes($r['hrg']) . "';\n";
			}?></select></td>'+
//Harga
'<td align="center"><input type="text" name="harga['+i+']" id="harga" style="text-align:right" onFocus="startCalculate()" onBlur="stopCalc()"/></td>'+
//jumlah 
'<td align="center"><select name="jumlah['+i+']" style="width:100px; text-align:center" onFocus="startCalculate()" onBlur="stopCalc()"><?
	for ($a=0; $a<=50; $a++) {
	echo "<option value=$a>$a</option>";
	}
?></select></td>'+
//Stock
'<td align="center"><input type="text" name="stock['+i+']" style="text-align:right" onFocus="startCalculate()" onBlur="stopCalc()"/></td>'+
//sub Total Harga
'<td align="center"><input type="text" name="Sub_totalharga['+i+']" style="text-align:right" onFocus="startCalculate()" onBlur="stopCalc()"/></td>'+
'<td align="center"><button type="button" class="del">Del</button></td>'+
'</tr>';
$(row).insertBefore("#last");
i++;
});
});
$(".del").live('click', function(){
$(this).parent().parent().remove();
});
<?php echo "$jsArray1";?>
</script>
Silahkan login untuk menjawab!
0
Loading...
Ario Dwi Wirawan · Dec 21, 2015 · 0 Suka · 0 Tidak Suka
assalammualaikum mas saya coba kok ada yg eror yah?, mohon pencerahannya mas

Warning: include(koneksi.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\penjualan\index.php on line 2

Warning: include() [function.include]: Failed opening 'koneksi.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\penjualan\index.php on line 2

Notice: Undefined variable: n in C:\xampp\htdocs\penjualan\index.php on line 43