$query = mysql_query("select * from master_material where nomor_normalisasi = $hint");
$dd=mysql_fetch_array($query);
if($dd)
{
$_SESSION['tempbarang'] = "$dd[0]#$dd[1]#$dd[2]";
$response =$_SESSION['tempbarang'];
$temp= array('tempbarang' => $response);
}
echo json_encode($temp);
setelah saya coba data yang dimasukan ke variable tersebut berhasilvar tempbarang;
function addTableRow(jQtable){
jQtable.each(function(){
$.ajax({
url:"gethint.php",
dataType:'json',
type:'GET',
success:function(resp){
alert('tidak terjadi error');
tempbarang = resp.tempbarang;
},
error:function(){
alert('terjadi error');
}
});
var brg = tempbarang;
var $table = $(this);
var n = parseInt(document.getElementById('nomor').value) + 1;
var qty = document.getElementById('qty').value;
if (qty<=0)
{
alert('QTY tidak boleh kosong atau minus');
}
else {
var brgs= brg.split('#');
var tds = '<tr>';
tds += '<td align=center>'+brgs[0]+'<input type="hidden" name="brg['+n+']" value="'+brgs[0]+'" /></td>';
tds += '<td>'+brgs[1]+'</td>';
tds += '<td align=center>'+qty+'<input type="hidden" name="qty['+n+']" id="qty['+n+']" value="'+qty+'" /></td>';
tds += '<td align=center class="delete" onClick="$(this).parent().remove(); minTotal('+qty+')"><a href="javascript:void(0)">Hapus</a></td>';
tds += '</tr>';
if($('tbody', this).length > 0){
$('tbody', this).append(tds);
}else {
$(this).append(tds);
}
document.getElementById('nomor').value = n;
}
});
}
tapi saya tidak mengerti kenapa selalu gagal, akhirnya saya mencoba melakukan pemanggilan dengan menggunakan $get.JSON seperti inivar tempbarang;
function addTableRow(jQtable){
jQtable.each(function(){
$.getJSON("gethint.php", function (data)
{
tempbarang = data.tempbarang;
});
var brg = qty = tempbarang;
var $table = $(this);
var n = parseInt(document.getElementById('nomor').value) + 1;
var qty = document.getElementById('qty').value;
if (qty<=0)
{
alert('qty tidak boleh kosong')
}
else {
var brgs= brg.split('#');
var tds = '<tr>';
tds += '<td align=center>'+brgs[0]+'<input type="hidden" name="brg['+n+']" value="'+brgs[0]+'" /></td>';
tds += '<td>'+brgs[1]+'</td>';
tds += '<td align=center>'+qty+'<input type="hidden" name="qty['+n+']" id="qty['+n+']" value="'+qty+'" /></td>';
tds += '<td align=center class="delete" onClick="$(this).parent().remove(); minTotal('+qty+')"><a href="javascript:void(0)">Hapus</a></td>';
tds += '</tr>';
if($('tbody', this).length > 0){
$('tbody', this).append(tds);
}else {
$(this).append(tds);
}
document.getElementById('nomor').value = n;
}
});
}
sebelumnya mohon maaf jika saya terlalu banyak bertanya, saya newbie masalah PHP <html>
<body>
<div>
<label class="kiri">Bilangan 1=</label>
<input type="radio" id="bil1" value="1" name="bilangan1" onClick="isi_bil1(this)" />1
<input type="radio" id="bil1" value="2" name="bilangan1" onClick="isi_bil1(this)" />2
<input type="radio" id="bil1" value="3" name="bilangan1" onClick="isi_bil1(this)" />3
<input type="radio" id="bil1" value="4" name="bilangan1" onClick="isi_bil1(this)" />4
<input type="radio" id="bil1" value="5" name="bilangan1" onClick="isi_bil1(this)" />5
<input type="radio" id="bil1" value="6" name="bilangan1" onClick="isi_bil1(this)" />6
</div>
<div>
<label class="kiri">Bilangan 2=</label>
<input type="radio" id="bil2" value="1" name="bilangan2" onClick="isi_bil2(this)" />1
<input type="radio" id="bil2" value="2" name="bilangan2" onClick="isi_bil2(this)" />2
<input type="radio" id="bil2" value="3" name="bilangan2" onClick="isi_bil2(this)" />3
<input type="radio" id="bil2" value="4" name="bilangan2" onClick="isi_bil2(this)" />4
<input type="radio" id="bil2" value="5" name="bilangan2" onClick="isi_bil2(this)" />5
<input type="radio" id="bil2" value="6" name="bilangan2" onClick="isi_bil2(this)" />6
</div>
<div>
<label class="kiri">Bilangan 3=</label>
<input type="radio" id="bil3" value="1" name="bilangan3" onClick="isi_bil3(this)" />1
<input type="radio" id="bil3" value="2" name="bilangan3" onClick="isi_bil3(this)" />2
<input type="radio" id="bil3" value="3" name="bilangan3" onClick="isi_bil3(this)" />3
<input type="radio" id="bil3" value="4" name="bilangan3" onClick="isi_bil3(this)" />4
<input type="radio" id="bil3" value="5" name="bilangan3" onClick="isi_bil3(this)" />5
<input type="radio" id="bil3" value="6" name="bilangan3" onClick="isi_bil3(this)" />6
</div>
<div>
<label class="kiri">Bilangan 4=</label>
<input type="radio" id="bil4" value="1" name="bilangan4" onClick="isi_bil4(this)" />1
<input type="radio" id="bil4" value="2" name="bilangan4" onClick="isi_bil4(this)" />2
<input type="radio" id="bil4" value="3" name="bilangan4" onClick="isi_bil4(this)" />3
<input type="radio" id="bil4" value="4" name="bilangan4" onClick="isi_bil4(this)" />4
<input type="radio" id="bil4" value="5" name="bilangan4" onClick="isi_bil4(this)" />5
<input type="radio" id="bil4" value="6" name="bilangan4" onClick="isi_bil4(this)" />6
</div>
<div id="hasilnya" name="hasilnya">Tempat hasil perkalian</div>
<form name="form1" method="post" action="">
<label>
<input type="submit" name="Submit" value="reset">
</label>
</form>
</body>
<script>
function isi_bil1(elm){
// isi elemen dengan id = bil1 dengan nilai dari radio button
bil1.value = elm.value;
}
function isi_bil2(elm){
// isi elemen dengan id = bil1 dengan nilai dari radio button
bil2.value = elm.value;
kalikan();
}
function isi_bil3(elm){
// isi elemen dengan id = bil1 dengan nilai dari radio button
bil3.value = elm.value;
kalikan();
}
function isi_bil4(elm){
// isi elemen dengan id = bil1 dengan nilai dari radio button
bil4.value = elm.value;
kalikan();
}
function kalikan(){
var bil1 = document.getElementById("bil1").value;
var bil2 = document.getElementById("bil2").value;
var bil3 = document.getElementById("bil3").value;
var bil4 = document.getElementById("bil4").value;
var hasil=bil1+bil2+bil3+bil4;
document.getElementById("hasilnya").innerHTML = "hasilnya adalah "+hasil+"<br /> by <em><strong>asligresik.wordpress.com</strong></em>";
}
</script>
</html>
<style>
div{
border-radius:5px;
padding:6px;
margin:4px;
border-bottom:2px solid gray;
}
div input{
border:1px solid gray;
}
div label.kiri{
width:100px;
}
</style>
<?php
$array = Array(
'2' => '50',
'3' => '60',
'4' => '12',
'5' => '23',
'12' => '43',
'13' => '43',
'28' => '54',
'29' => '34',
'30' => '54',
'31' => '23',
'32' => '43',
'53' => '23',
"90" => "43",
"91" => "43",
"92" => "43",
"93" => "54",
"94" => "89",
"95" => "12",
"96" => "11",
);
echo '<pre>';
print_r($array);
echo '</pre>';
?>
<?php
include "koneksi.php";
$sql = "SELECT * FROM tbpeg ORDER by nama";
$hasil = mysql_query($sql);
?>
<tr>
<td><label for="cbonm[0]"></label>
<select name="cbonm[0]" onChange="cari(this.value)">
<option value=" " selected> </option>
<?php
while($data=mysql_fetch_array($hasil)){
echo "<option value=$data[nip]>$data[nama]</option>";
}
?>
</select>
</td>
<td><input name="txtpangkat[0]" type="text" id="txtpangkat" readonly="readonly" /></td>
<td><input name="txtdivi[0]" type="text" id="txtdivi" size="25" readonly="readonly" /></td>
<td><textarea name="txtperanan[0]" id="txtperanan"></textarea></td>
<td><button type="button" class="del">Hapus</button></td>
</tr>
<tr id ="last">
<td colspan="5"><button type="button" id="addRow"> Tambah </button></td>
</tr>
</table>
<table width="646" border="0">
<tr>
<td width="544" align="right"><input type="submit" name="cmdsimpan" id="cmdsimpan" value=" Simpan " /></td>
<td width="10" align="right"> </td>
<td width="80" align="right"><input type="submit" name="cmdbatal" id="cmdbatal" value=" Batal " /></td>
</tr>
</table>
</form>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
var i = 1;
$(function(){
$("#addRow").click(function(){
row = '<tr>'+
'<td><select name="cbonm['+i+']"</select></td>'+
'<td><input type="text" name="txtpangkat" readonly="readonly['+i+']"/></td>'+
'<td><input type="text" name="txtdivi" size="25" readonly="readonly['+i+']"/></td>'+
'<td><textarea name="txtperanan['+i+']"/></td>'+
'<td><button type="button" class="del">Hapus</button></td>'+
'</tr>';
$(row).insertBefore("#last");
i++;
});
});
$(".del").live('click', function(){
$(this).parent().parent().remove();
});
</script>
Yg saya mau setelah di klik button tambahnya, nah cbonm yg baru keluar, valuenya sama dengan yg pertama dan bisa masuk ke txt yg baru juga. intinya sama seperti yg row pertama.