I want to populate my select option using ajax, when i clicked the "Detail" button. the option is from the database, i've tried :
The Select Option :
<select id="update_listboxstock" size="5" class="form-control">
</select>
Button's Code :
<td style="text-align:center;">
<button onclick="GetMenuDetails('.$row['kode_menu'].')" class="btn btn-warning" data-toggle="modal" data-target="#update_record_modal">Perbarui/Detail</button>
</td>
Javascript :
function GetMenuDetails(id) {
$.get("function_and_ajax/ajax.php",{
ajx:"GetRecipe",
kode_menu:id
},function(result){
$("update_listboxstock").html(result);
});
}
AJAX :
include("function_connection.php");
if(isset($_GET['ajx'])){
if($_GET['ajx'] == 'GetRecipe'){
$kode_menu = $_GET['kode_menu'];
GetRecipe($kode_menu);
}
}
function GetRecipe :
function GetRecipe($kode_menu){
$conn = getConnection();
echo "<option>".$_SESSION["kode_menu"]."</option>";
$query = "SELECT DISTINCT S.NAMA_BARANG AS NAMA_BARANG, MD.JUMLAH AS JUMLAH, S.SATUAN AS SATUAN, S.KODE_STOK AS KODE_STOK FROM STOCKS S, MENUDETAILS MD, MENUS M WHERE S.KODE_STOK = MD.KODE_STOK AND MD.KODE_MENU = '".$_SESSION["kode_menu"]."'";
$conn=getConnection();
$result = $conn->query($query);
if ($result->num_rows > 0){
while($row = $result->fetch_assoc()){
echo "<option value=".$row['kode_stok'].">
".$row['NAMA_BARANG'].
" - ".
$row['JUMLAH']." ".$row['SATUAN']."
</option>";
}
}
}
Sorry for my bad English...