When closing modal return to the source form passing parameters

0

I'm doing a query on my DB in a janela modal , now after the query is done, I need to click a button to send the selected parameters to the calling page and to play those parameters in some inputs , I had previously done this using a url returning the desired values by closing the modal , but had a problem, this caused a new page load causing previously populated data from other fields to be lost.

I did this by clicking the submit button:

<button type="button" class="btn btn-primary btn-mini" data-toggle="modal" onclick="EnviaDados()"> enviar </button>
<input id="NomeCooperante" type="hidden" value="<?php echo $Retorno->NomeCooperante; ?>" />

And on the return page like this:

function EnviaDados() {
    $('#ModalCooperante').modal('hide'); 

    // var valor = $('input[type="text"][name="NomeCooperante"]').val();    
    var NomeCoop = $(this).attr("NomeCooperante");
    alert("COOPERANTE: " + NomeCoop);

}

I made some tests, the result of the alert is:

COOPERANTE: [Object HTMCollection]

What I have is this, the search:

AndthefieldsIneedtofillinonreturn.

    
asked by anonymous 25.11.2016 / 14:11

1 answer

0

The solution to my problem was this:

I passed the parameters obtained in the search for the call of a function, it looks like this:

<button type="button" class="btn btn-primary btn-mini" data-toggle="modal" data-dismiss="modal" onclick="mostraDados('<?php echo $Retorno->IdCooperante; ?>','<?php echo $Retorno->NomeCooperante; ?>','<?php echo $Retorno->IdPropriedade; ?>','<?php echo $Retorno->LocalVistoria; ?>','<?php echo $Retorno->IdMunicipio; ?>','<?php echo $Retorno->IdUF; ?>')"> enviar </button>

On the calling page, I retrieved the parameters and assigns them to the fields as follows:

function mostraDados(pIdCooperante,pNome,pIdPropriedade,pVistoria,pUF,pIdMunicipio) {   

    // ATRIBUINDO VALORES RETORANDOS AOS CAMPOS
    $("#ID").val(pIdCooperante); 
    $("#Cooperante").val(pNome); 
    $("#Propriedade").val(pIdPropriedade);
    $("#Vistoria").val(pVistoria);
    $("#UF").val(pUF);
    $("#Municipio").val(pIdMunicipio);  

    $("#ModalCooperante").closemodal(); 

}
    
30.11.2016 / 14:21