How can I click on an HTML row then show the selection values of the row in input text?
I've tried like this, but what shows up in the input text only the first row even though I click the second row and so on..
div class="col-md-1 col-md-1 col-xs-1">
<button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#myModal">...</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" scrollY:380>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Category</h4>
</div>
<div class="modal-body">
<table id="datatable-responsive" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>Id Event Category</th>
<th>Event Category</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<% objLOV.forEach(function (lov) { %>
<tr>
<td id="field_id" onclick="myFunction()">
<%= lov.id %>
</td>
<td id="field_category" onclick="myFunction()">
<%= lov.event_category %>
</td>
<td id="field_description" onclick="myFunction()">
<%= lov.description %>
</td>
</tr>
<% }) %>
</tbody>
</table>
and my javascript
<script>
function myFunction() {
document.getElementById("id_type").value = document.getElementById("field_id").textContent.trim();
document.getElementById("event_category").value = document.getElementById("field_category").textContent.trim();
document.getElementById("description").value = document.getElementById("field_description").textContent.trim();
}
</script>
"id_type" , "event_category" , "description"
is my input text type id