-1
Good night,
I have a checkbox list and need to send to a modal the information of which checkbox are with status 'ckecked'.
I’m using the code below, but I’m not getting it, can help me please?
form
<form id="form">
<ul>
<li><input type="checkbox" value="1" name="disponivel">1</li>
<li><input type="checkbox" value="2" name="disponivel">2</li>
<li><input type="checkbox" value="3" name="disponivel">3</li>
</ul>
<button id="salvar" type="submit" class="btn btn-primary" data-toggle="modal" data-target="#teste" onclick="obterMarcados();">Enviar</button>
</form>
modal
<div class="modal fade" id="teste" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Reservados </h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Valor:</label>
<input type="text" class="form-control" id="recipient-name">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
.JS
<script>
var botao = document.querySelector('#salvar');
var form = document.querySelector('#form');
botao.addEventListener('click', function (event) {
event.preventDefault();
$('#teste').on('show.bs.modal', function (event) {
var numeros = form.disponivel.value;
var modal = $(this)
modal.find('.modal-title').text('Reservar Números ' + numeros)
modal.find('.modal-body input').val(numeros)
});
});
</script>