I have this dropdown in codeigniter Nama Barang
. This is the code :
<div class="form-group">
<label>Nama Barang</label>
<div class="form-inline">
<select id="nama" class="form-control namabarangsearch col-sm-10" name="name" required onchange="getNamaTransaksi()">
<option value="">-- Nama Barang --</option>
<?php
foreach ($groups as $group) {
echo '<option value="' . $group->stok. '" value="' . $group->name . '">' . $group->name . '. Stok : ' . $group->stok . '</option>';
}
?>
</select>
</div>
<small class="form-text text-muted" id="sisa"></small>
</div>
Then the script :
<script>
function getNamaTransaksi() {
var x = document.getElementById("nama").value;
document.getElementById("sisa").innerHTML = "Nama barang : " + x;
}
</script>
What should i do if i want to have 2 value from the option, so i can call it on the script? I've tried to do this :
<script>
function getNamaTransaksi() {
var x = document.getElementById("nama").value['$group->stok'];
document.getElementById("sisa").innerHTML = "Nama barang : " + x;
}
</script>
But it gives me undefined value. What am i doing wrong here? also sorry if my code is messy.
source https://stackoverflow.com/questions/69772944/having-2-different-values-in-one-option-dropdown
Comments
Post a Comment