Submit form using modal bootstrap

Asked

Viewed 624 times

1

I’m trying to submit a form contained in modal boostrap, but I don’t know how to perform this action.

Look down at my code:

Pagina Principal:

<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 Home 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 happens that it triggers the event click, however, when clicking the button, it shows the variable as "Undefined". How I can redeem the value of the select field?

Any help thanks =D

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');

});

1

You can capture the event directly from the button. No need to go through the modal methods and find.

$(".btn-atualizar-status").on('click', function() {
    alert('Testando o clique no botão atualizar');
});
  • Hello Lucas, I tested it this way, but it didn’t work. when I click on the button, nothing happens.

  • I used " $('#idDivModal4'). on('click', '.btn-update-status', Function()? " and it worked =D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.