When closing modal return to the source form passing parameters

Asked

Viewed 691 times

0

I’m making a query in my comic in a janela modal, now after the query made, need by clicking a send button the selected parameters to the calling page and play these parameters in some inputs, had previously done so using a url return the desired values by closing modal, but had a problem, this caused a new page loading causing the previously filled data from other fields to be lost.

I did this by clicking send 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 did some tests, the result of Alert is being:

COOPERANTE: [Object HTMCollection]

What I have is this, the search:

inserir a descrição da imagem aqui

And the fields I need to fill in on the return.

inserir a descrição da imagem aqui

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 was 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 assigned 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(); 

}

Browser other questions tagged

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