1
Guys I have this JS to be able to duplicate a record:
function duplicarCampos(){
var clone = document.getElementById('div_dados_historico').cloneNode(true);
var destino = document.getElementById('destino');
destino.appendChild (clone);
var camposClonados = clone.getElementsByTagName('input');
for(i=0; i<camposClonados.length;i++){
camposClonados[i].value = '';
}
}
function removerCampos(id){
var node1 = document.getElementById('destino');
node1.removeChild(node1.childNodes[0]);
}
and that HTML:
<div id="div_dados_historico" style="display: none;">
<h3>HISTÓRICO PROFISSIONAL</h3>
<label>Empresa</label>
<input type="text" name="empresa1[]" placeholder="Empresa" />
<label>Cargo</label>
<input type="text" name="cargo1[]" placeholder="Cargo" />
<label>Periodo</label>
<input type="text" name="periodo1[]" placeholder="Periodo" />
<label>Atividades</label>
<textarea rows="4" cols="50" name="atividades1[]" placeholder="Atividades" > </textarea>
<center><div>
<img src="<?php echo $URL ?>site/view/images/add.jpg" style="cursor: pointer;" onclick="duplicarCampos();">
<img src="<?php echo $URL ?>site/view/images/cross.jpg" style="cursor: pointer;" onclick="removerCampos(this);">
</div> </center>
</div>
<div id="destino"> </div>
However I wanted that as I was opening a "MORE", it appears company2, company3, company4.... .n. How could I do that in JS ?
Where is the HTML of
#div_dados_historico
? where do you want to insert this_2
,_3
etc.?– Sergio
The #div_dados_historico is where the JS form is to duplicate when pressing the "add.jpg" button, then I want that when the guy clicks "add.jpg", it appears empresa2 , cargo2, periodo2....
– Caroline Silveira
I realize that div is for cloning, my doubt is where is this HTML...
– Sergio
html is inside the div, so : <div id="div_dados_historico" style="display: None;">
– Caroline Silveira
Is it secret to put all the HTML? do you want "good answers" or "half answers"? The more information you give the more we can help...
– Sergio
so all html is this msm kkkkk, ta so oh :
– Caroline Silveira
I put here https://jsfiddle.net/pycassu9/ so you can understand better
– Caroline Silveira
How will you receive all this data if the possibilities will be
N
, besides, why send them as array if you are incrementing thenames
?– Kenny Rafael
I thought the Names would be to record in the rs bank, now I’m in doubt rs, so I don’t know much, I try to implement in the code and keep hitting
– Caroline Silveira
I think it’s the same of that question.
– Renan Gomes