I get the problem to create custom autonumber in dialog form jquery easy ui..
I Have the a function in controller like this..
public function getCode()
{
if(!isset($_POST))
show_404();
$query = "SELECT MAX(kode_barang) as maxID FROM tb_barang";
$hasil = mysql_query($query);
$data = mysql_fetch_array($hasil);
$idMax = $data['maxID'];
$noUrut = (int) substr($idMax, 1, 4);
$noUrut++;
$newID = "B" . sprintf("%04s", $noUrut);
$queryData = $query->row_array();
$phpVar = array( "STATUS" => $newID);
echo json_encode ($phpVar) ;
}
and I call that function from view, the javascript function like this..
<script> function makeAjaxCall()
{
$.ajax({
type: "post",
data: $('#form').serialize(),
url: "http://192.168.0.77/ci_jquery/barang/getCode",
cache: false,
success: function(json){
var obj = jQuery.parseJSON(json);
var r = obj['STATUS'];
document.forms["form"]["kode_barang"].value = r;
}
});
}
</script>
And this is my dialog form.
<div id="dialog-form" class="easyui-dialog" style="width:300px; height:400px; padding: 10px 20px" closed="true" buttons="#dialog-buttons">
<form id="form" method="post" novalidate>
<table border="0">
<tr>
<div class="form-item">
<td width="100"><label for="type">Kode Barang </font></td>
<td><input type="text" name="kode_barang"/></td>
</tr>
</div>
Thanks for reply and attention.