This is my code example:
<select name="codethings"id="products">
<option value="0">--choose--</option>
<?php
include 'config.php';
$sql="select * from thing where status='S01'";
$call=mysqli_query($connect,$sql);
while($data=mysqli_fetch_array($call)){ ?>
<option value="<?php echo $data['codethings']; ?>" data-price="<?php echo ['price'];
? >" ><?php echo $data['codethings'];?>-<?php echo $data['namet'];?>(<?php echo $data['price']; ?>)</option>
<?php } ?>
</select>
<br>
Price:
<input type="text" name="price" id="priceInput" value="" disabled="disabled"><br>
Script
<script>
$(function () {
$('#products').change(function () {
$('#priceInput').val($('#products option:selected').attr('data-price'));
});
});
</script>
The code i reference (Automatically show price when we select the ID in PHP)
It is not work after i select. How i want to make it work to make the price display automatically after i select.