In another question, you have been able to help me to store the values of some input
of a popup, to pass to the parent page.
Summary.jsp (parent page)
<input type="button" onclick="test();" value="Palavras" />
<div id="idPai"></div>
function test(){
window.showModalDialog('saida.jsp',null,'status:off;center:yes;scroll:no;');
}
In the popup, there is a function, addCampos()
, for the user to create multiple fields input
.
saida.jsp (popup)
<div id="campoPai"></div>
<input type="text" id='ctxt' name="campo[]" class="form-control">
<input type="button" value="Adicionar campos" onclick="addCampos()">
<button class="btn btn-success" onclick="enviaDados();">Envia Dados</button>
<script type="text/javascript">
var qtdeCampos = 0;
function addCampos() {
var objPai = document.getElementById("campoPai");
var objFilho = document.createElement("div");//Criando o elemento DIV;
objFilho.setAttribute("id","filho"+qtdeCampos);//Definindo atributos ao objFilho
objPai.appendChild(objFilho);//Inserindo o elemento no pai
//Escrevendo algo no filho recém-criado:
document.getElementById("filho"+qtdeCampos).innerHTML = "<input type='text' id='ctxt"+qtdeCampos+"' name='campo[]'>\n\<input type='button' onclick='removerCampo("+qtdeCampos+")' value='Apagar campo'>";
qtdeCampos++;
}
function removerCampo(id) {
var objPai = document.getElementById("campoPai");
var objFilho = document.getElementById("filho"+id);
//Removendo o DIV com id específico do nó-pai:
var removido = objPai.removeChild(objFilho);
}
</script>
In the method below, it is the main part of the other question, where the values (an array) are passed to the parent page.
<script language="javascript">
function enviaDados(){
$("#idPai").html(""); // Aqui irá resetar o conteudo da div.
$('input[id^="ctxt"]').each(function(){
$("#idPai").append("<p><b> Valor do Imput: "+$(this).val()+"</b></p>");
});
window.close();
}
</script>
Update
My problem is that I do not know how to use (pick up) this value on the parent page. What I need is: the user will type several words in the popup, when closing the popup, the words typed will be compared with a java array, and thus only the typed words that are contained in that array will be shown on the screen.