Submit form using modal bootstrap

1

I'm trying to submit a form contained in modal boostrap, but I'm not sure how to do this.

See below my code:

Home Page:

<div id="idDivModal4" class="modal fade">
  <div class="modal-dialog modal-lg">
      <div class="modal-content">
      </div>
  </div>
</div>

<a class="btn btn-block btn-primary top10 btn-sm" href='#idDivModal4' role='button' data-toggle='modal' data-load-remote='atualizar-status/<?php echo $codigo;?>' data-remote-target='#idDivModal4 .modal-content' aria-hidden='true' > Atualizar Status</a>

Page (update-status) containing modal form:

<div class="modal-body">

<select name="campo_status " id="campo_status " class="form-control div-campo-status" required>
<option value="Sim">Sim</option>
<option value="Não">Não</option>
</select>

<div class="modal-footer">
<button type="button" class="btn btn-default"
data-dismiss="modal">Cancelar</button>
<a class="btn-atualizar-status">Atualizar</a>
</div>

On the Main page, include the following jquery:

$('#idDivModal4').on('click', '.btn-atualizar-status', function(){
{
     var campo_status = $(this).parent().find('.div-campo-status').val();  
     alert(campo_status);
});

It turns out that it triggers the click event, however, when you click the button, it shows the variable as "undefined". How can I retrieve the value of the select field?

Any help thank you = D

    
asked by anonymous 29.09.2016 / 05:25

2 answers

1

Add an id to the Modal tag, after, just grab the element by the id and add the onclick function, for example:

$("#atualizar").click(function() {

alert ('Testando o clique no botão atualizar');

});
    
29.09.2016 / 05:34
1

You can capture the event directly from the button. You do not have to go through modal and find methods.

$(".btn-atualizar-status").on('click', function() {
    alert('Testando o clique no botão atualizar');
});
    
29.09.2016 / 05:39