-4
I have a input
that after being filled and pressed Enter, she creates a list with checkbox
's. The problem is that when it is populated again, it edits the already created list item and I want to create a new item, not edit the previous one.
I want to get the list filled in with the input
, create several li
's and not just one and keep editing/overwriting it. How can I do this?
// verifica se a tecla apertada é o enter
function OnEnter(evt) {
var key_code = evt.keyCode ? evt.keyCode :
evt.charCode ? evt.charCode :
evt.which ? evt.which : void 0;
if (key_code == 13) {
return true;
}
}
var j = 1;
function recarrega(e) {
if(OnEnter(e))
{
var p = document.getElementById('Foo');
var filhos = p.childNodes;
for (i = filhos.length - 1; i >= 0; i--) {
if (filhos[i].tagName == 'LI') {
p.removeChild(filhos[i]);
}
}
var tarefa = document.getElementById("my_span").value;
document.getElementById("my_span").value = "";
var li = document.createElement('li');
p.appendChild(li);
li.id = 'my_span'+ j;
li.innerHTML = "<input type='checkbox' id='ckb" + j + "' value='" + j + "' onclick='my_fun(" + j + ");'>" + tarefa;
j++;
return false;
}
else
{
return true;
}
}
// quando marco o checkbox ele risca a string da li
function my_fun(j) {
var chkbox = "ckb" + j;
var my_span = "my_span" + j;
var msg = chkbox + " " + my_span;
if ($("#ckb"+ j).is(':checked')) {
document.getElementById(my_span).style.textDecoration = 'line-through';
} else {
document.getElementById(my_span).style.textDecoration = 'none';
}
}
<form>
<label for="ctarefa">Tarefas:</label>
<input onkeypress="return recarrega(event);" type="text" id='my_span'/><br />
<div class="boxLista">
<ul id="Foo">
</ul>
</div>
</form>
Welcome to Stack Overflow in English! Welcome to [en.so]. Your question is very broad, the standard of the community are objective questions and have at least one correct answer, as can be seen in the [help] link [Ask]. This question of yours, in addition to being very broad, may give rise to questions. Take a [tour] tour and then you can [Dit] your question so we can help you.
– Randrade
Come on. Before trying to understand your problem I’ll give you some tips: 1. Almost all the content of the site is someone who needs helping, soon put help/help/help and the like in the title is something extremely redundant. 2. We know by tags which language or technology you need help with, so it is also redundant to put this in the question title (save rare exceptions). 3. The title should be a (very) brief description of your problem, something that gives you an "idea" of what you need. 4. Take the time to write your question, explain your problem in a way that [+]
– Jéf Bueno
[+] someone who doesn’t know anything about your project can help you. See [Ask], how to create a minimum, complete and verifiable example and visit [tour], this will help you (and a lot). You can edit your question at any time by clicking on [Edit]. By the way, welcome to [pt.so].
– Jéf Bueno
What do you mean, "and keep editing the same"? What’s missing from the code you have? You can describe better what you can’t get to work?
– Sergio
whenever you fill in the input and give enter creates a <li> with the value filled in and clears the input, when I fill in again I would like to create another <li> with the new entry but my code edits the previous <li>
– Marcio Vinicios
Marcio, you need to [Edit] your question for it to be voted for reopening. Please check out the jbueno tips, are important.
– brasofilo
I gave an improved explanation I believe I can already understand the part where I’m struggling
– Marcio Vinicios