My dear ones,
I have a table of users, and for each user I have a button that opens a modal:
{% for item in lista_usuarios %}
<tr>
<td>{{ item.first_name }}</td>
<button data-target="modal1" class = "oi" type = "button" value="{{item.id}}" class = "btn waves-effect waves-light blue" data-index="{{item.id}}" onclick="$('#modal1').modal('open');" >
<i class="large material-icons">clear</i>
</button>
</td>
</tr>
As you can see, the value of this button is already taking the id of each user, this is correct.
In the modal, I have a label and I need the value of this id to be passed to it.
<input type="text" class="usuario">
<script>
$(document).ready(function(){
$(".oi").each(function() {
$(this).click(function() {
alert("teste");
$('.modal').modal();
var id = $(".oi").val();
alert(id);
$(".usuario").val(id);
});
});
});
</script>
Modal is running and 2 alerts as well. However, it is passing the same user id always, passing only the id of the first user to the label within the modal.