I use this code in fetching the data from the database.
$result = $con->query("SELECT firstname,lastname FROM employee");
And then render like bellow:
<select name="employees">
<option value="">Select Employee</option>
<?php while ($rows = $result->fetch_assoc()) {
$employee_name = $rows['firstname'] . " " . $rows['lastname'];
echo "<option id = emprecord_id value = '$employee_name'>$employee_name</option>";
}
?>
</select>
I need to know how can I get the ID (or if there is anyway) of the selected value because I will insert values for the selected option in another table. Like i get the data from the employee table and If the Name of the employee was selected, it will proceed to another page we're I will insert new data for its payroll.
You could access the selected option with selectedIndex :
let tSelectedIndex = document.querySelector('select[name=languages]').selectedIndex;
let tID = document.querySelectorAll('select[name=languages] option')[tSelectedIndex].id;