1
On another question, they were able to help me about storing the values of some input of a popup, to move to the parent page.
Summary.jsp (father)
<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 popup, there is a function, addCampos(), for the user to create several 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, is the main part of the other question, is where is passed the values (an array) 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>
Updating
My problem is that I don’t know how to use (catch) this value on the parent page. What I need is: the user will type several words in the popup, when closing the popup, the typed words will be compared with a java array, and so only the typed words that are contained in this array will be shown on the screen.
Buddy, you can take the values from the
eachputting the$(this).val()in an array in the objectwindowusing the functionArray.push().– Lucas Fontes Gaspareto
can you give an example? I’m not used to HTML/Javascript programming
– Pacíficão
@Peaceful Opa, you need to take input values and play for the parent jsp ( here is meant as the actual rendered html), or for java?
– Matheus
@Matheus need to play for the parent JSP. There I will use it in a java function.
– Pacíficão
@Peace I think it’s a bit confusing, in jsp it means like html with its Javascript functions, if you want to play for java, because it doesn’t use a normal form?
– Matheus
@Matheus In short, what I need to do is: Get these words typed in the popup and compare them to a vector that’s in java. I will only show in the page the words that were typed and are in the vector in java. It’s less confusing now?
– Pacíficão
@Peace Now I understand what you need. But you will have to edit the question, attaching such a problem so they can help you.
– Matheus
@Matheus there is some way to buy in real-time the values of
eachwith those of thearray java?– Lucas Fontes Gaspareto
@devgaspa Yes, assuming the programmer took the java list and passed it to an array in JS. Then just compare the values of each with the array coming from java.
– Matheus
@Matheus then, suppose there is a
array JSvalues from java, only usingif(arrayJsComValoresDoJava.indexOf($(this).val()) != -1)I can verify the existence of the value.– Lucas Fontes Gaspareto
@devgaspa At first yes, and that would solve the question.
– Matheus