-1
Next, I assigned a value to a button, and passed to my function through the onClick.
Only now, I’d like to take that amount that’s in index
and input my modal... How can I do this?
My button that calls the function:
<button data-var="<?= $cont ?>" onClick="funcaoModal(this)" class="dropdown-item" data-toggle="modal" data-target="#modal-atualizar">Atualizar></button>
My job:
function funcaoModal(element) {
var index = $(element).data('var');
}
My modal:
<div class="modal fade" id="modal-atualizar">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Atualizar</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="solicitacao.php" method="POST">
<div class="form-group">
<label class="input-form col-md-6" for="ticket">Número do ticket:</label>
<input class="input-form form-control col-md-12" type="text" id="ticket" name="ticket" value="" readonly>
</div>
I wanted the value of the variable to be pro value
of my input, of the modal.
Thanks Mt Andre, it worked! I only had a doubt, that date-var I did not know, I saw in another tutorial. I can pass more than one element on it? If I wanted to pass more than one datum for example, would I?
– Alissonx
Good!! Look, this one
data-var
was a custom attribute that the tutorial used, you can have as many as you want, and call them as you want tbm,id-produto
for example, already about passing more than one element, as if it were an array, I think q not, but from there passing multiple attributes maybe solve for you– andre_luiss