I have a radiobutton list that is populated from MySQL. A function to be called when the selected radiobutton changes. I would like to be get the ID of the selected item.
<ul id="radio" class="input-list">
<?php
$stmt = mysqli_prepare($link, "SELECT id, name, price FROM cases ORDER BY price");
$stmt->execute();
$stmt->bind_result($case_id, $case_name, $case_price);
while($stmt->fetch()) {
echo '<li>
<input class="selectedoptions" id="'.$case_id.'" name="config-case" value="'.$case_price.'" type="radio" onchange="updateImage(this.id);">
<label class="sub-label" for="'.$case_id.'">'.$case_name.' [£'.$case_price.']</label>
</li>';
}
$stmt->close();
>
</ul>
JS:
<script>
function updateImage(caseid) {
var selectmenuID = document.getElementById(caseid);
console.log(selectmenuID);
}
<script>
Attempting to get the id of the selected item is not successful. This is the console output:
<input class="selectedoptions" id="32" name="config-case" value="24"
type="radio" onchange="updateImage(this.id);">
I would like to get the 32 (the id). How can I do this? Thank you,