I am working with an array that is retrieved from my database, which contains objects. This array includes hours, employee IDs, and a list of employees on the web page. My goal is to display the number of hours assigned to a specific employee when clicking on their name.
var makeup_hrs = api_resp.makeup_data[key];
for (var i = 0; i < makeup_hrs.length; i++) {
var obj = makeup_hrs[i];
console.log(obj);
for (var o in obj) {
var y = obj[o];
console.log("make up hours ", y, "id: ", emp_id)
var x = document.getElementById("makeUpHours").innerHTML = y;
console.log(x);
// $('#makeUpHours').html(y);
}
}
Although I am able to successfully retrieve the number of hours assigned to each employee along with their ID through console logs, I am facing an issue with displaying this information via innerHTML. It only displays the last hours value rather than matching it to a specific employee.
The console output shows data for two employees currently stored in my database:
make up hours 4 id: 2891
make up hours 7 id: 1978
Below is the relevant HTML code within a Bootstrap modal where the hours information should be displayed:
<div class="form-group"> <label class="col-sm-3"> Hours </label>
<span id="makeUpHours"></span></div>
A modal window pops up when an icon is clicked, with each icon corresponding to a specific employee ID.
https://i.sstatic.net/0cL6V.jpg
https://i.sstatic.net/D4XHw.jpg
https://i.sstatic.net/AZAIN.jpg
The correlation between employee IDs and hours is correctly established when these values are logged together.