Nanya mas.. Masalah Edit Combobox didalam Dialog Form
Saya g bisa ambil option yang udah diselect ke database.. Mohon bantuannya ya mas.
<?php
include "connect.php";
$result = mysql_query("SELECT a.no_urut,a.nomer_surat,a.nomer_agenda,a.perihal,a.tgl_surat,
a.tgl_terima,b.nama_pengirim FROM surat_masuk a,pengirim b
WHERE a.id_pengirim=b.id_pengirim ");
?>
<!DOCTYPE html>
<html>
<head>
<title>DataTables</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="media/js/jquery.js" type="text/javascript"></script>
<script src="media/js/jquery.dataTables.js" type="text/javascript"></script>
<script src="media/js/jquery.ui.dialog.js" type="text/javascript"></script>
<script src="media/js/jquery-ui-1.8.20.custom.min.js" type="text/javascript"></script>
<style type="text/css">
@import "media/css/demo_table_jui.css";
@import "media/themes/smoothness/jquery-ui-1.8.4.custom.css";
@import "media/css/demos.css";
</style>
<style>
*{
font-family: arial;
}
th.hide{
display: none;
}
td.no_urutCell{
display: none;
}
}
</style>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$('#datatables').dataTable({
"sPaginationType":"full_numbers",
"aaSorting":[[2, "desc"]],
"bJQueryUI":true
});
$("#waiting").hide();
$( "#dialog-edit" ).dialog({
autoOpen: false,
resizable: false,
height: 200,
width: 350,
modal: true,
buttons: {
"Update": function() {
var
ano_urut = $("#no_urutedit").html();
anomer_surat = $("#nomer_suratedit").val();
anomer_agenda = $("input#nomer_agendaedit").val();
aperihal = $("input#perihaledit").val();
atgl_surat = $("input#tgl_suratedit").val();
atgl_terima = $("input#tgl_terimaedit").val();
anama_pengirim = $("input#nama_pengirimedit").val();
aact= 'edit';
$.ajax({
type: "POST",
url: "postdata.php",
data: {"no_urut":ano_urut,"nomer_surat":anomer_surat,"nomer_agenda":anomer_agenda,"perihal":aperihal,
"tgl_surat":atgl_surat,"tgl_terima":atgl_terima,"nama_pengirim":anama_pengirim,"act":aact},
timeout: 10000,
beforeSend: function(){},
complete: function(){},
cache: false,
success: function(result){
if (result=='success'){
//ubah isi data table sesuai dengan perubahan yang terjadi
objRow.find(".nomer_suratCell").html($("input#nomer_suratedit").val());
objRow.find(".nomer_agendaCell").html($("input#nomer_agendaedit").val());
objRow.find(".perihalCell").html($("input#perihaledit").val());
objRow.find(".tgl_suratCell").html($("input#tgl_suratedit").val());
objRow.find(".tgl_terimaCell").html($("input#tgl_terimaedit").val());
objRow.find(".nama_pengirimCell").html($("input#nama_pengirimedit").val());
$("#waiting").hide();
}else{alert(result);}
},
error: function(error){$("#waiting").hide();alert('request timeout, please try again.');}
}
);
$("#waiting").show();
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
<!--Akhir dari inisialisasi dialog jQuery-->
})
function EditData(obj){
var no_urut = obj.parent().parent().find(".no_urutCell").html();
nomer_surat = obj.parent().parent().find(".nomer_suratCell").html();
nomer_agenda = obj.parent().parent().find(".nomer_agendaCell").html();
perihal = obj.parent().parent().find(".perihalCell").html();
tgl_surat = obj.parent().parent().find(".tgl_suratCell").html();
tgl_terima = obj.parent().parent().find(".tgl_terimaCell").html();
nama_pengirim = obj.parent().parent().find(".nama_pengirimCell").html();
$("#no_urutedit").empty().append(no_urut);
$("input#nomer_suratedit").val(nomer_surat);
$("input#nomer_agendaedit").val(nomer_agenda);
$("input#perihaledit").val(perihal);
$("input#tgl_suratedit").val(tgl_surat);
$("input#tgl_terimaedit").val(tgl_terima);
$("input#nama_pengirimedit").val(nama_pengirim);
objRow = obj.parent().parent(); //simpan object row
$( "#dialog-edit" ).dialog("open");
}
</script>
</head>
<body>
<div>
<table id="datatables" class="display">
<thead>
<tr>
<th class="hide">No.</th>
<th width="100">No Surat</th>
<th width="100">No Agenda</th>
<th width="200">Perihal</th>
<th width="50">Tgl Surat</th>
<th width="50">Tgl Terima</th>
<th width="150">Pengirim</th>
<th width="50">Pilihan</th>
</tr>
</thead>
<tbody>
<?php
while ($baris = mysql_fetch_array($result)){
echo "<tr>
<td class='no_urutCell'>".$baris['no_urut']."</td>
<td class='nomer_suratCell'>".$baris['nomer_surat']."</td>
<td class='nomer_agendaCell'>".$baris['nomer_agenda']."</td>
<td class='perihalCell'>".$baris['perihal']."</td>
<td class='tgl_suratCell'>".$baris['tgl_surat']."</td>
<td class='tgl_terimaCell'>".$baris['tgl_terima']."</td>
<td class='nama_pengirimCell'>".$baris['nama_pengirim']."</td>
<td align='right'>
<a class='edit' href='#' onClick='EditData($(this))'>Edit</a>
</td>
</tr>";
}
?>
</tbody>
</table>
<div id="dialog-edit" title="Edit Data Karyawan">
<form>
<table border="0">
<tr>
<td><label for="no_urut">No.</label></td>
<td><div id="no_urutedit"></div></td>
</tr>
<tr>
<td><label for="nomer_surat">Nomer Surat</label></td>
<td><input type="text" name="nomer_suratedit" id="nomer_suratedit" value="" class="text ui-widget-content ui-corner-all" /></td>
</tr>
<tr>
<td><label for="nomer_agenda">Nomer Agenda</label></td>
<td><input type="text" name="nomer_agendaedit" id="nomer_agendaedit" value="" class="text ui-widget-content ui-corner-all" /></td>
</tr>
<tr>
<td><label for="perihal">Perihal</label></td>
<td><input type="text" name="perihaledit" id="perihaledit" value="" class="text ui-widget-content ui-corner-all" /></td>
</tr>
<tr>
<td><label for="tgl_surat">Tgl Surat</label></td>
<td><input type="text" name="tgl_surat" id="tgl_suratedit" value="" class="text ui-widget-content ui-corner-all" /></td>
</tr>
<tr>
<td><label for="tgl_terima">Tgl Diterima</label></td>
<td><input type="text" name="tgl_terimaedit" id="tgl_terimaedit" value="" class="text ui-widget-content ui-corner-all" /></td>
</tr>
<tr>
<td><label for="nama_pengirim">Pengirim</label></td>
<td><select name="pengirim" id="pengirim">
<option>--Pilih--</option>
<?php
// query untuk menampilkan daftar pengirim
$query = "SELECT a.nama_pengirim,b.id_pengirim FROM pengirim a, surat_masuk b WHERE no_urut=$baris";
$hasil = mysql_query ($query);
while ($data = mysql_fetch_array ($hasil))
{
$selected = '';
if($data['id_pengirim'] == $baris){
$selected = 'selected="selected"';
}
echo '<option value="'.$data['id_pengirim'].'" '.$selected.'>'.$data['nama_pengirim'].'</option>';
}
?>
</select></td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>