I want to fetch the value from jQuery's autofill dropdown which comes from mysql for the max input attribute and I have tried this code
$a = mysqli_query($connect,"SELECT ID_PENUNJANG, BIAYA, STOK FROM penunjang_pesta ");
$array = array();
foreach ($a as $item) {
$array[$item['ID_PENUNJANG']] = $item;
}
$json = 'var itema = ' . json_encode($array) . ';';
and this my script
<script>
<?php echo $json;?>
$("#PENUNJANG").change(function(){
var sid = $(this).val();
$("input[name='BIAYA']").val(itema[sid].BIAYA);
$("input[name='STOK']").val(itema[sid].STOK);
// $("input[name='JUMLAH']").val(itema[sid].STOK).max; i'm try this too
$("input[name='JUMLAH']").attr({
"max": val(itema[sid].STOK),
"min": 1
});
});
</script>
but my max value is not showing.
You should change val(itema[sid].STOK)
to itema[sid].STOK
the full code will be like this:
<script>
<?php echo $json;?>
$("#PENUNJANG").change(function(){
var sid = $(this).val();
$("input[name='BIAYA']").val(itema[sid].BIAYA);
$("input[name='STOK']").val(itema[sid].STOK);
// $("input[name='JUMLAH']").val(itema[sid].STOK).max; i'm try this too
$("input[name='JUMLAH']").attr({
"max": itema[sid].STOK,
"min": 1
});
});
</script>