I have a simple program, which takes the value of a id1
text box and after pressing the button it throws this text (function Enviar1
) to another text box id2
. What I need to do is delete this id2
and show the text in items.
function Enviar1() {
var valor = document.getElementById('id1').value;
document.getElementById('id2').value = valor;
}
<input id="id1" type="text" />
<input id="id2" type="text" />
<input id="botao" type="button" value="Ok" onclick="Enviar1()">
I would like every time I type text in id1
and press OK, it would be creating new items, without deleting the first, to create items one underneath the other.
Thanks for the help! :)
....
Already updating the content with the help of colleagues ... just to be clearer, what I have so far is like this. I would like to be able to edit the already written and sent items now, and even erase them if possible. Thank you for your help!! : D
Update with pure JS
ServiceReportMaker Test
var menu_dropdown = document.getElementById("selecao");
menu_dropdown.addEventListener("change", function(){
var valor_selecionado = menu_dropdown.options[menu_dropdown.selectedIndex].value;
if(valor_selecionado == "personalizar"){
document.getElementById("div_personalizar").style.visibility= "";
} else {
document.getElementById("caixa1").value = valor_selecionado;
document.getElementById("div_personalizar").style.visibility = "hidden";
}
});
function Enviar1()
{
var ul = document.getElementById("itens");
var li = document.createElement("li");
var valor = document.getElementById('id1').value;
li.appendChild(document.createTextNode(valor));
ul.appendChild(li);
}
<select id="selecao">
<option value="" selected > Selecionar empresa </option>
<option value="1ª opção" >Primeira opção aqui</option>
<option value="2ª opção">Segunda opção aqui</option>
</select>
<input id="caixa1" type="text" />
<div id="div_personalizar" style="visibility: hidden;"></div>
<input type="text" id="id1" />
<input type="button" value="OK" onclick="Enviar1()" />
<ul id="itens"></ul>