0
I have a simple program that takes the value of a text box id1
and after pressing the OK button plays this text (function Enviar1
) to another text box id2
. What I need to do is eliminate this id2
and display 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 a text in id1
and press OK, he was creating new items, without deleting the first, to create items under each other.
Thanks for your help! :)
....
Already updating the content with the help of colleagues... Just to be clear, what I have so far is like this. I would like to be able to edit the items already written and sent now, and even delete them if possible. Thanks for the help!! D
Update with pure JS
Test Servicereportmaker
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>
Eduardo, I believe this new role should be the subject of a new question here by Sopt. As you did not specify the whole problem initially, the answers previously given to this amendment would not make much sense, as they would only answer part of the question. Feel free to create another question by placing the code you have, describing the need to delete and change the items.
– Woss