I have a dynamically generated table where I can add rows like
function addNewRow() {
var table = document.getElementById("employee-table");
var rowCount = table.rows.length;
var cellCount = table.rows[0].cells.length;
var row = table.insertRow(rowCount);
row.setAttribute("id", "line-" + count_row.toString());
for (var i = 0; i < cellCount; i++) {
var cell = row.insertCell(i);
if (i == 0) {
cell.innerHTML =
'<select class="form-select" aria-label="Default select example">' +
"<option selected>Open this select menu</option>" +
'<option value="\x80\x80\x80\x80\x80\x80">Pausa</option>' +
'<option value="\x80\x90\x80\x80\x80\x80">Altezza+</option>' +
'<option value="\x90\x80\x80\x80\x80\x80">Altezza-</option>' +
"</select>";
} else if (i < cellCount - 2) {
cell.innerHTML = '<input type="number" class="form-control" />';
} else if (i < cellCount - 1) {
cell.innerHTML =
'<button value="delete" onclick="deleteRow(this)" type="button" class="btn btn-outline-danger">' +
'<i class="bi bi-x-circle"></i>' +
"</svg></button> ";
} else {
cell.innerHTML =
'<span class="input-group-text"><i class="handle"><i class="bi bi-grip-horizontal"></i></i></span> ';
cell.className = "handle";
}
}
count_row++;
// load_js();
}
every row has its unique ID
Now, I would like to access the currently selected option inside the select
form in the first column in a javascript function when a button is clicked
is there a way to do it in javascript?
I'm using bootstrap and I'm seeing that selecting different options, the selected tag doesn't change in the HTML so I can't understand how to get the actual selected one if nothing changes