In my application, Here adding new rows with the dynamic ID assigned from the loop.
In the view, I'm creating a Purchase Order, and here I adding the rows to the table.
So Here When the Select
value changes, I want to get that changed row Id and the Selected Id for a Javascript to send it to the controller.
How to get that in javascript?
var counter = 1;
$(function () {
$("#add").click(function () {
var newRow = $(
'<tr id="tablerow' +
counter +
'"> ' +
"<td>" +
'<label id="CountItems"><strong>' +
counter +
"</strong></label>" +
"</td>" +
'<td width="40%">' +
'<select class="form-select js-dropdown" name="Item_Id[' +
counter +
']" id="ItemId"' + counter+ 'required="required" ' +
"</select>" +
"</td>" +
'<td width="10%">' +
'<input type="text" class="form-control" name="Qty[' +
counter +
']" value="1" id="Qty"' + counter + ' required="required" />' +
"</td>" +
'<td width="10%">' +
'<input type="text" class="form-control" name="AcidStables[' +
counter +
']" value="" required="required" />' +
"</td>" +
'<td width="20%">' +
'<input type="text" class="form-control" name="Unit_Price[' +
counter +
']" value="0.00" id="UnitPrice"' + counter + ' required="required" />' +
"</td>" +
'<td width="20%">' +
'<input type="text" class="form-control" name="Line_Total[' +
counter +
']" value="0.00" id="LineTotal"' + counter + ' required="required" />' +
"</td>" +
"<td>" +
'<button type="button" class="btn btn-danger" onclick="removeTr(' +
counter +
');">x</button>' +
"</td>" +
"</tr>"
);
var selectElement = newRow.find("select"); // Find the <select> element in the new row
// Populate the <select> element with options
dropdownOptions.forEach(function (option) {
var optionElement = $("<option>").val(option.Value).text(option.Text);
selectElement.append(optionElement);
});
newRow.appendTo("#submissionTable");
counter++;
return false;
});