1
Colleagues,
I have a system where the customer clicking a button opens a modal bootstrap for him to register a matter. I need to make sure that when registering, the Box where the materials are.
I tried the code below:
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" style="background-color: #CF850F; color: #FFF; font-weight: bold">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> Cadastrar nova matéria</h4>
</div>
<div class="modal-body">
<div class="form-group">
<form method="post" name="post" id="contact-form">
<div id="success"></div>
<label for="exampleInputEmail1">Matéria:</label>
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>
</div>
<input type="text" class="form-control" name="NovaMateria" maxlength="150" id="novovalor">
</div>
</form>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-warning" data-dismiss="modal" id="submit"><i class="fa fa-floppy-o fa-lg" aria-hidden="true"></i> Salvar</button> <button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
</div>
</div>
</div>
</div>
When I put text field and put commented code, it works:
<script>
// Atualizar
/* $(function(){
$("#submit").click(function(){
$("#materia").val($("#novovalor").val());
});
});
*/
$(document).ready(function(){
$("#submit").click(function(){
$('#novovalor').change(function(){
$('#materia').load($('#novovalor').val());
});
});
});
</script>
And the Combox:
<select name="Materias" class="form-control select2" id="materia" data-placeholder="Selecione a matéria" style="width: 100%;">
............
</select>
If I understand correctly, you can already take the return of the modal and need to add in combobox.. that being so,
$("#materia").append("<option value='" + id_novovalor + "'>" + novovalorretornadodomodal + "</option>");
– rLinhares