In the JSP page, there is a dynamic drop-down list generated as shown below:
<table BORDER=4 BORDERCOLOR=ORANGE width="300px">
<tr>
<td>Model:</td>
<td><select name="model" id="model">
<c:forEach items="${model_list}" var="item">
<option value="${item.modelId}">${item.modelName}</option>
</c:forEach>
</select></td>
</tr>
</table>
The goal is to update the selected value of the dropdown based on another value obtained from this section:
<table BORDER=4 BORDERCOLOR=ORANGE width="120px" id="product_table">
<c:forEach items="${product_list}" var="car">
<tr>
<td><INPUT type="checkbox" name="chk_group" value="${car.carId}" /></td>
<td><c:out value="${car.carId}" /></td>
<td><c:out value="${car.model.modelName}" /></td>
<td><c:out value="${car.model.modelId}" /></td>
</table>
Below is the script intended for this purpose:
function findRowNumber() {
var rowIdx;
var rowData = new Array();
var table = document.getElementById('product_table');
var rows = table.getElementsByTagName('tr');
var selectedRow;
for ( var i = 0; i < rows.length; i++) {
rows[i].onclick = function() {
rowIdx = this.rowIndex;
selectedRow = rows[rowIdx];
document.getElementById('model').value = selectedRow.cells[3].innerHTML;
}
}
}
Please note that selectedRow.cells[3].innerHTML
returns 3 but the value does not change.